base_controller控制器基类

调用流程

继承关系


base_render提供的函数

display

对html模板文件进行编译后输出

function display($tmpl_file, $app_id=null, $fetch=false)

参数
    $tmpl_file  html模板文件路径
    $app_id     html模板文所在所在app
    $fetch      是否直接输出,false直接输出|true 返回编译后的内容,可以嵌套其他页面

pre_display

对用display编译后的html进行再次编译,或则是说对编译后的内容进行修改

此方法需要注册一个service实现 base_render_pre_display

single

私有方法实例化一个类

private function single($classname)

参数
    $classname   类的名字
返回
    object

fetch

fetch方法是调用display,是将display中的$fetch=true,使页面可嵌套输出

function fetch($tmpl_file,$app_id=null)

参数$tmpl_file,$app_id和display参数一样

tmpl_cachekey

定义模板生成编译文件的key(也就编译文件的文件名)的后缀,为一个数组,可定义多个后缀信息

public function tmpl_cachekey($key,$value)

参数
    string          $key编译文件key这个数组中的一个键值
    string|array    $value编译文件key这个数组对因键的值
返回
    array

ui

实例化base_component_ui类,这个类是系统中对一些UI组件的定义,此方法是在编译的时候调用

对html模板中使用了系统的UI组件的代码进行编译

function &ui()

compile_id

对模板生成编译文件的key的值(数组)进行md5,这个key值为:文件名+tmpl_cachekey方法定义的后缀

function compile_id($path)
参数
    string  $path模板文件的路径,包含文件
返回
    string

base_render提供的service

tpl_source.

应用场景

自定义模板文件,如邮件模板,短信模板

一般是我们定义好一个邮件模板文件,先是将规则定义好,根据规则把模板文件存储到数据库

在要使用这个模板文件的时候则到数据库中把模板文件获取到,在根据规则把数据填充到模板文件中

再用base_render中的fetch方法进行编译返回

使用方法
  • 注册service tpl_source.$name
    <service id="tpl_source.messenger">
        <class>b2c_messenger_tmpl</class>
    </service>
    
  • service类的写法
    此service类的方法及作用
    
    last_modified       返回模板文件最后修改的时间
    get_file_contents   返回自定义模板文件
    
    <?php
    /**
     * ShopEx licence
     *
     * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (https://www.shopex.cn)
     * @license  https://ecos.shopex.cn/ ShopEx License
     */

    class b2c_messenger_tmpl{

        
    //获取模板文件的最后修改时间
        
    public function last_modified($tplname){
            
    $systmpl app::get('b2c')->model('member_systmpl');
            
    $aRet $systmpl->getList('*',array('active'=>'true','tmpl_name'=>$tplname));//获取到自定义模板
            
    if($aRet){
                return 
    $aRet[0]['edittime'];
            }
            return 
    time();
        }

        public function 
    get_file_contents($tplname){
            
    $systmpl app::get('b2c')->model('member_systmpl');
            
    $aRet $systmpl->getList('*',array('active'=>'true','tmpl_name'=>$tplname));
            if(
    $aRet){
                return 
    $aRet[0]['content'];//返回获取到的模板文件(代码)
            
    }
            return 
    null;
        }
    }
    ?>
  • 调用display或则fetch是文件名参数的写法
    function fetch($tmpl_file,$app_id=null)
    一般来说$tmpl_file文件为文件的路径:'site/default.html'然而对于使用tpl_source.$name service的方式来说
    
    $tmpl_file写法是:($name:$tmpl_name)
    $name       <service id="tpl_source.messenger">例子来说 $name = messenger
    $tmpl_name  是能够获取到模板文件的一个标识
    

base_render_pre_display

应用场景

如果模板文件经过系统编译过以后,需要对编译后的文内容再一次进行修改,或则替换,则需要注册此service

使用方法
  • 注册service
    <service id="base_render_pre_display">
        <class>base_service_render</class>
    </service>
    
  • service类的写法
    pre_display(&$content)
    
    参数
        $content    传引用,得到数据是display经过系统编译后的内容
    
    <?php
    /**
     * ShopEx licence
     *
     * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (https://www.shopex.cn)
     * @license  https://ecos.shopex.cn/ ShopEx License
     */


    class base_service_render{
        public function 
    pre_display(&$content){
            
    $content base_storager::image_storage($content);//对编译后的内容$content进行替换
        
    }//End Function

    }//End Class

base_controller提供的函数

begin

开启事务,设置错误或成功时返回的URL地址,设置用户自定义的错误处理函数_errorHandler

和 end 配合使用

参数
    string|array    当参数为字符串时,是自己拼的URL,当参数为数组时,则为gen_url对应的写法

例1

$this->begin('index.php?app=b2c&ctl=admin_brand&act=index');
例2
$this->begin(array('app'=>'b2c','ctl'=>'admin_brand','act'=>'index'));

end

配合begin使用,事务处理,提交或回滚。进行提示成功或失败提示

提示跳转调用的是desktop_controller下的splash方法

function end($result=true,$message=null,$url_params=null,$params=array()){
参数
    bool    $result=true则提交,$result=false则回滚
    string  $message返回的提示信息
    string  提示跳转的URL。如果参数为空并且begin带了参数,那么就用begin带的参数

            当参数为字符串时,是自己拼的URL,当参数为数组时,则为gen_url对应的写法
    array   splash的最后一个参数

function save(){
    $this->begin('index.php?app=b2c&ctl=admin_brand&act=index');
    $objBrand = &$this->app->model('brand');
    $brandname = $objBrand->dump(array('brand_name'=>$_POST['brand_name'],'brand_id'));
    if(empty($_POST['brand_id']) && is_array($brandname)){
         $this->end(false,app::get('b2c')->_('品牌名重复')); //错误提示
    }
    $_POST['ordernum'] = intval( $_POST['ordernum'] );
    $data = $this->_preparegtype($_POST);
    $this->end($objBrand->save($data),app::get('b2c')->_('品牌保存成功'));
}

endonly

配合begin使用事物处理,错误则用错误处理函数进行显示,正确则不处理

function endonly($result=true){
参数
    bool    $result=true则提交,$result=false则回滚

splash

信息提示函数,在base只是一个接口类似的东西,实现功能只是跳转,在系统中用的最多还是site_controller或则desktop_controller

中的对base_controller中的splash的重构的方法

function splash($status='success',$url=null,$msg=null,$method='redirect',$params=array())

page

在系统中很少使用,用的最多的还是site_controller中的page或则是desktop_controller中的page

调用的base_render中的display或则是自己注册一个service theme 自己写一个display方法,自定义编译规则

function page($detail){
参数
    string  $detail需要编译的文件路径

base_controller提供的serviec

theme

此service由base_controller下的page方法提供,service类的方法为dispaly

实现功能和bsae_render下的display的功能差不多,可以在这个方法中自定义

编译规则进行编译,之后在返回给编译后的内容