Thread: Smarty trouble
View Single Post
  #4 (permalink)  
Old 07-29-2007, 12:32 PM
misaak misaak is offline
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Quote:
Originally Posted by SpotSec View Post
hmm what smarty implementation are you using?
smarty view

PHP Code:
<?php
require_once 'Smarty/Smarty.class.php';
require_once 
'Zend/View/Abstract.php';


class 
My_View_Smarty extends Zend_View_Abstract
{
    protected 
$_engine;
    
    function 
__construct($params null)
    {
    
parent::__construct($params); 
        
        
$this->_engine = new Smarty();
        
        if (
is_array($params)) {
            foreach (
$params as $key=>$value) {
                
$this->_engine->$key $value;
            }
        }
    }

    public function 
getSmartyEngine()
    {
        return 
$this->_engine;
    }

    public function 
__set($key$val)
    {
        
$this->_engine->assign($key$val);
    }

    public function 
__get($key)
    {
        return 
$this->_engine->get_template_vars($key);
    }

    public function 
__isset($key)
    {
        
$var $this->_engine->get_template_vars($key);
        return !
is_null($var); 
    }

    public function 
__unset($key)
    {
        
$this->_engine->clear_assign($key);
    }

    public function 
assign($spec$value null)
    {
        if (
is_array($spec)) {
               
$this->_engine->assign($spec);
            return 
$this;
        }
    
        
$this->_engine->assign($spec$value);
    return 
$this;
    }

    public function 
clearVars()
    {
        
$this->_engine->clear_all_assign();
    return 
$this;
    }

    public function 
render($name)
    {
        
$this->_file $this->_script($name);
    
$dir  substr($this->_file0strlen($this->_file) - strlen($name));
    
$this->_engine->template_dir $dir;
        
        return 
$this->_engine->fetch($name);
    }
        
    public function 
setPluginPath($dir)
    {
        
$this->_engine->plugins_dir $dir;
    return 
$this;
    }

    public function 
addPluginPath($dir)
    {
        
$this->_engine->plugins_dir[] = $dir;
    return 
$this;
    }

    public function 
setCompilePath($dir)
    {
        
$this->_engine->compile_dir $dir;
    return 
$this;
    }
    
    public function 
setCachePath($dir)
    {
        
$this->_engine->cache_dir $dir;
    return 
$this;
    }
    
    public function 
setCacheLifetime($seconds)
    {
        
$this->_engine->cache_lifetime $seconds;
    return 
$this;
    }
    
    public function 
setBasePath($path$classPrefix 'Zend_View')
    {
    
parent::setBasePath($path$classPrefix);
        
$path        rtrim($path'/');
        
$path        rtrim($path'\\');
        
$path       .= DIRECTORY_SEPARATOR;
        
$classPrefix rtrim($classPrefix'_') . '_';
        
$this->setScriptPath($path 'templates');
    
$this->setPluginPath($path 'plugins');
        
    return 
$this;
    }
    
    public function 
addBasePath($path$classPrefix 'Zend_View')
    {
    
parent::addBasePath($path$classPrefix);
        
$path        rtrim($path'/');
        
$path        rtrim($path'\\');
        
$path       .= DIRECTORY_SEPARATOR;
        
$classPrefix rtrim($classPrefix'_') . '_';
        
$this->addScriptPath($path 'templates');
    
$this->addPluginPath($path 'plugins');

        return 
$this;
    }
    
    function 
_run()
    {            
    }
}
and in bootstrap
PHP Code:
$view = new My_View_Smarty($config->smarty->toArray());
$viewRenderer Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setView($view)
                      ->
setViewSuffix('tpl'); 
Reply With Quote