开发者

Using Codeigniter with Modular Extensions and Smarty

I am working on Jasonayre bravenewignition system and want to add this project Smarty. What can i do for usin开发者_Go百科g a HMVC system and Smarty together?


Well i did it just some days ago, that's the step for integrating smarty system.

  1. Download Smarty from http://www.smarty.net/download
  2. Put the smarty folder inside application/third_party
  3. Create smarty.php file in application/libraries and paste this

    require_once(APPPATH.'third_party/Smarty/libs/Smarty.class.php');
    
    class CI_Smarty extends Smarty {
    
    protected $CI;
    private $module;
    
    public function __construct()
    {
        parent::__construct();
    
        // get CI istance
        $this->CI =& get_instance();
        // fetch the calling module, need to check for views inside it
        $this->module = $this->CI->router->fetch_module();
    
        // path
        $this->setCompileDir(APPPATH . "cache/smarty/compiled");
        $this->setCacheDir(APPPATH . "cache/smarty/cached");
        $this->setTemplateDir(APPPATH . "views/templates");
    
        // to use $this inside our views/template
        $this->assignByRef('this', $this->CI);
    
        log_message('debug', "Smarty Class Initialized");
    }
    
    public function display ($template, $cache_id = null, $compile_id = null, $parent = null) {
        // automatically add .tpl extension if there is not in $template
        if (strpos($template,'.') === FALSE) {
            $template .= '.tpl';
        }
        if ( !empty($this->module)){
            $template = APPPATH . 'modules/' . $this->module . '/views/' . $template;
        }
        // call the original smarty function
        parent::display($template, $cache_id, $compile_id, $parent);
    }
    }
    
    /* End of file Smarty.php */
    /* Location: ./application/libraries/Smarty.php */
    

ps: sorry for indentation

Now you can use smarty with $this->load->library('smarty') or automatically load it adding smarty to $autoload in the configuration file.

Hope this help! ^^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜