必要扩展库
php_xsl, php_curl, php_openssl
URL参数的意义
Section是最大的单元,只有一级。Section之下有多级的Category,最小的单元是Enity。但其实所有单元,都是同一组结构,存储于#__sobipro_object表中,对系统来说没什么分别。
sid = Section ID & Category ID & Enity ID
pid = parent section ID
源数据调试
sobipro的模板结构基于XSLT,也就是源数据是XML,经过XSLT加工后会转换为HTML,即PHP -> XML -> XSLT -> HTML,所以修改模板也就是修改XSLT文件。如果要深度修改模板,有时候需要修改源数据,修改XML输出,所以查看输出XML成为了模板调试的关键。后台设置Allow Raw XML Output为YES,前台在URL后面添加&xml=1,就会输出XML源数据。
XSLT编辑器
XSLT是标准格式文档,所以多数编辑器都会支持,而如果有条件,可以使用微软的visual studio 2012,会提供很好的语法提示。
目录结构
控制器 : components/com_sobipro/lib/ctrl/*
数据模型 : components/com_sobipro/lib/models/*
视图 : components/com_sobipro/lib/views/*
默认模板 : components/com_sobipro/usr/templates/default/*
模块模板 : components/com_sobipro/usr/templates/front/modules/*
字段:components/com_sobipro/opt/fields/*
源数据调整
模板的数据源是XML数据,XML数据从视图提供,例如category.php, entry.php, section.php
视图程序中只会生成array数据,而sobipro的框架会自动把它转换为XML。不过关于node的array描述有固定的格式,格式如下:
array(
'_complex' => 1,
'_data' => 'data',
'_attributes' => array('class' => 'item')
);
常用代码:
// 得到section下的所有category
SPLoader::loadController( 'section' );
$SPSectionCtrl = new SPSectionCtrl();
$SPSectionCtrl->setModel( SPLoader::loadModel( 'section' ) );
$sectionModel = $SPSectionCtrl->getModel();
$sectionModel->load(1);
$dbCategories = $sectionModel->getChilds( 'category', true );
// 得到某entry的name属性
SPFactory::Entry($id)->get( 'name' );
// 得到指定field name的文本值
$fields = SPFactory::Entry($id)->getFields();
echo $fields['field_firstname']->getRaw();
// 得到指定field的输入框
$fields = SPFactory::Entry($id)->getFields();
SPLoader::loadClass( 'mlo.input' );
$fields['field_firstname']->field();
// 得到image field的路径
$product = SPFactory::Entry( $id );
$files = SPConfig::unserialize($product->getField($fid)->getRaw());
echo $files['image'];
PS: image是一种field type,可以查field的代码得知field的属性
从其它地方载入sobipro框架
require_once ( implode( DS, array( JPATH_ROOT, 'components', 'com_sobipro', 'lib', 'sobi.php' ) ) );
Sobi::Init( JPATH_ROOT, JFactory::getConfig()->getValue( 'config.language' ), $sid );
模板说明(后台可以查)
category/view.xsl |
Default category view template inclusive top menu, navigation, entries and categories. |
common/alphamenu.xsl |
Template for the alpha menu. |
common/catchooser.xsl |
Sub-Template for the category chooser for the edit entry form. |
common/category.xsl |
Template for a single category in the categories list. |
common/entries.xsl |
Template to display the block with all entries (entriesLoop) within a category or the search function. Build the structure of all entries and calls the "vcard" template while displaying single entry. |
common/manage.xsl |
Display the managing functions like edit entry, approve aso, within an entry. |
common/navigation.xsl |
Template for the site navigation. |
common/topmenu.xsl |
Template for the top menu. |
common/vcard.xsl |
在category或者search中的单个enity |
css/default.css |
Default CSS file. |
css/edit.css |
CSS file with extra styles for the add antry or edit entry page. |
css/search.css |
CSS file with extra styles for the search function. |
entry/details.xsl |
Template for the entry details view page. |
entry/edit.xsl |
Template for the add entry or edit entry page. |
feeds/rss.xsl |
Template for Atom/RSS feeds. |
js/edit.js |
JavaScript functions for the edit entry page. |
js/osx.js |
SimpleModal OSX Style Modal Dialog. |
js/search.js |
JavaScript functions for the search page. |
listing/alpha.xsl |
Alpha-Listing template. |
payment/payment.xsl |
View of the payment after an entry has been added. |
payment/submit.xsl |
Template for the preview of the payment. |
search/view.xsl |
Template for the search function. |
section/view.xsl |
Template for the section main view. |
template.php |
PHP file with additional functions to use within templates. |