Mosets Tree开发笔记

简述:

 
主要元素有Category, listing, field
Category下有多个listing,listing下可以有多个field,field可以用于搜索与展示,而每个field都有字段类型。除了mtree内的核心字段外,可以加入自定义字段。字段类型类都继承一个公共类(mFieldType),并实现所有字段功能,后台也可以添加新的mFieldType类来满足复杂的需求。也就是说,如果现有字段提供的功能没有满足需求,可以修改对应类型的mFields基类,或者添加新的mFieldType类。以自定义方式新建的类型是通过后台的Manage field types页来创建类实现,并且代码将存于数据库。
 
结构:
 
各页面的模板 components/com_mtree/templates/m2/
字段类型基类 administrator/components/com_mtree/mfields.class.php
 
字段类(mFields)的成员函数:
 
getSearchHTML 前台对应字段搜索功能的HTML输出
getInputHTML 后台对应字段录入的HTML输出
getOutput 前台对应字段HTML输出
getJSValidation javascript验证代码
 
自定义字段逻辑例子:
 
Name of the field type: texttype
 
class mFieldType_texttype extends mFieldType {
function getOutput($view=1) {
return $this->getValue();
}
 
function getInputHTML() {
$html .= sprintf('<input type="text" name="%s" value="%s" />', $this->getInputFieldName(1), $this->getValue());
return $html;
}
}
 
排序:
 
mtree.tools.php中的customFieldsSort函数,用于处理自定义字段排序
 
mFieldType类常用功能:
 
$this->getParam('showCounter',1); 取得参数
$this->getName(); 取得字段名
$this->arrayFieldElements 得到Elements的值,后台可以设置这个值
$this->getValue(); 取得管理员设置的值
$this->getInputFieldName(1) 取得表单字段名
 
模板:
 
page_前缀是主页面,sub_前缀是子页面。主页面包含若干个子页面
 
page_listing.tpl.php (listing detail 页)
sub_listingDetails.tpl.php (listing detail 子页)
sub_map.tpl.php
sub_reviews.tpl.php
 
sub_listingSummary.tpl.php (listing summary 子页)
 
模板调用:
 
global $savantConf;
$savant = new Savant2($savantConf);
$savant->assign('template_value', value);
$savant->display( 'page.tpl.php' );
 
-----------------所有模板可用通用----------------
 
附件图片链接:
$this->jconf['live_site'] . $this->mtconf['relative_path_to_listing_small_image'] . $image->filename
 
图片位置参数:
relative_path_to_listing_small_image
relative_path_to_listing_medium_image
relative_path_to_listing_original_image
 
-----------(sub_listingDetails.tpl.php) start :------------
 
前台取字段值:
$this->fields->getFieldById(字段ID)->getValue()
 
# display image
$this->fields->getFieldById(23)->getOutput(1)
 
# not display image
$field = $this->fields->getField();
if($field->fieldType == 'image')
{
$this->fields->next();
continue;
}
 
# filter field
if(in_array($field->getId(), array(cf_id))) {
$this->fields->next();
continue;
}
 

----------(sub_listingDetails.tpl.php) end;-----------------

posted @ 2013-04-14 11:05  猫之良品  阅读(680)  评论(0编辑  收藏  举报