Welcome Guest, Not a member yet? Register   Sign In
multiple sites, 1 codebase, using symlinks (with smarty)
#10

[eluser]Pygon[/eluser]
Just a note -- your Smarty loader isn't of the best design.

Code:
class MySmarty extends Smarty{

    var $smarty;
    
    function MySmarty()
    {
        $this->smarty = new Smarty();
        $this->smarty->template_dir = APPPATH . "templates";
        $this->smarty->compile_dir = APPPATH . "templates_c";
        $this->smarty->cache_dir = APPPATH . "cache";
        $this->smarty->config_dir = APPPATH . "configs";
        $this->smarty->compile_check = true;
        $this->smarty->debugging = true;
        log_message('debug', "Smarty Class Initialized");
    }
    
    function assign($key,$value)
    {
        $this->smarty->assign($key,$value);
    }
    
    function display($template)
    {
        $this->smarty->display($template);
    }

}

Note that when you call load->module("MySmarty"), you are effectively creating a new object of MySmarty class, which is also creating a new object of Smarty class, which is already extended by MySmarty.

Effectively you are creating two instances of Smarty each time you load MySmarty -- $this->MySmarty->cache_dir and $this->MySmarty->Smarty->cache_dir exist but are different values.

I would assume that the intention was to create one object (not having the ability to create multiple smarty objects).

This is what I use, based on some code I've run into and my own design:
Code:
class MySmarty extends Smarty {
    
    function MySmarty(){
        $this->Smarty();
        
        $config =& get_config();
        
        $this->template_dir = ! empty($config['smarty_template_dir']) ? $config['smarty_template_dir'] : BASEPATH."application/views/smarty/templates";
        $this->compile_dir = ! empty($config['smarty_compile_dir']) ? $config['smarty_compile_dir'] : BASEPATH."application/views/smarty/templates_c";
        $this->cache_dir = ! empty($config['smarty_cache_dir']) ? $config['smarty_cache_dir'] : BASEPATH."application/views/smarty/cache";
        $this->config_dir = ! empty($config['smarty_config_dir']) ? $config['smarty_config_dir'] : BASEPATH."application/views/smarty/config";
        
        //Eliminates URL Helper requirement
        $CI =& get_instance();
        $site_url = $CI->config->slash_item('base_url');

        $this->assign("site_url",$site_url);
    }

}

Load smarty as normal:
$this->load->module("MySmarty");
Use it as normal:
$this->MySmarty->assign() -- etc.

Enjoy the reduction of memory usage per script.


Messages In This Thread
multiple sites, 1 codebase, using symlinks (with smarty) - by El Forum - 10-25-2007, 10:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB