Hi,
Haven't looked at code.. I suppose you used the one from manual.
As long as you adhere to the interface by Zend_View_Abstract you should be all set. The idea of all this is at some point when you want
to migrate to other view solution you do this with little to no hassle.

I first used this solution for smarty myself and then migrated to Zend_View as seems the right choice for me now. Pretty easy transaction
Good luck.

Regards,

Roberto Bouza wrote:
Julian,

I have this piece of code from my library.

This is the actual library which is the one who is going to generate the View. Then on your bootstrap you'll have to create a Helper_ViewRenderer and assign the newly created View_Smarty object to it.

I did this code on 1.0.3, just yesterday I upgraded to 1.5 PR, fixed some things here and there and everything was working again.

Any advice from the Zend masters on this? I hope I'm on the right track. This is working but I want to be sure that I'm not shooting out of range here.

Thank you.


<?php
/*
 * Smarty libraries cannot be loaded with the Zend_Loader yet!
 */
require_once "Smarty/Smarty.class.php";
Zend_Loader::loadClass("Zend_View_Abstract");

class View_Smarty extends Zend_View_Abstract {
private $_smarty_config;
    private $_smarty;

    public function __construct(Zend_Config $init, $init_web_tag) {
if (isset($init) && !is_null($init_web_tag)) { $this->_smarty_config = new Zend_Config_Xml($init->root->path . $init->configuration->path . $init->configuration->files->smarty, $init_web_tag);
            $this->_smarty = new Smarty();
        } else {
throw new Exception("View_Smarty: config parameter not initialized");
        }
/*
         * Configuring Smarty
         */
        if (!isset($this->_smarty_config->compile_directory)) {
throw new Exception('compileDir is not set for '.get_class($this));
        } else {
$this->_smarty->compile_dir = $init->root->path . $this->_smarty_config->compile_directory;
        }

        if ( isset($this->_smarty_config->configuration_directory) ) {
$this->_smarty->config_dir = $init->root->path . $this->_smarty_config->configuration_directory;
        }

        if ( isset($this->_smarty_config->plugin_diretory) ) {
$this->_smarty->plugin_dir[] = $init->root->path . $this->_smarty_config->plugin_directory;
        }

        parent::__construct();
        $this->setEncoding('UTF-8');
}

    public function getEngine()    {
return $this->_smarty; }

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

    public function __isset($key) {
$var = $this->_smarty->get_template_vars($key); if ($var) {
            return true;
        }
return false; }

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

    public function assign($spec,$value = null)    {
if ($value === null) {
            $this->_smarty->assign($spec);
        } else {
            $this->_smarty->assign($spec,$value);
        }
}

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

    protected function _run() {
$this->strictVars(true);

        $this->_smarty->assign_by_ref('this',$this);

        $templateDirs = $this->getScriptPaths();

        $file = substr(func_get_arg(0),strlen($templateDirs[0]));
        $this->_smarty->template_dir = $templateDirs[0];

        echo $this->_smarty->fetch($file);
} }

?>

On Feb 25, 2008, at 8:02 AM, Julian Davchev wrote:

Have you tried the example in the manual regarding Smarty?


Stefan Sturm wrote:
Hello,

I want to use Smarty( or perhaps another Template Engine ) with ZendFramework. So I tried google and found a lot Tutorials on how to do it. But they are very old and they all take a different approach.

So I thought, I ask here for somesone who is using this combination and can help me out with some tipps :-)

Thanks for your Help,
Stefan Sturm



Reply via email to