Hi,
I'd like to recommend you implement Zend_View interface instead of extend the
abstract class and the render method can be simply like this without any
problem:
public function render($name)
{
return $this->_smarty->fetch($name);
}
if you look into Smarty's source code, you will find the display() method calls
fetch()
and prints the output.
Just my two cents.
Jason.
highland <[EMAIL PROTECTED]> wrote:
Hello
I created my own class extending Zend_View_Abstract and including smarty.
I wanted to be able to use smarty templates and zend render on the same
object.
Here is my code:
class MyView extends Zend_View_Abstract
{
private $_smarty = false;
public function __construct($data = array())
{
parent::__construct($data);
$config = Zend::registry('config');
$this->_smarty = new Smarty();
$main_path = $config->path->server.$config->path->homepage;
$this->_smarty->template_dir =
$main_path.$config->smarty->template_dir;
$this->_smarty->compile_dir =
$main_path.$config->smarty->compile_dir;
$this->_smarty->config_dir = $main_path.$config->smarty->config_dir;
$this->_smarty->cache_dir = $main_path.$config->smarty->cache_dir;
}
protected function _run($template=null)
{
print parent::render($template);
}
public function display($template)
{
$this->_smarty->display($template);
}
public function assign($var, $value=null)
{
if (is_string($var))
{
$value = @func_get_arg(1);
$this->_smarty->assign($var, $value);
}
elseif (is_array($var))
{
foreach ($var as $key => $value)
{
$this->_smarty->assign($key, $value);
}
}
else
{
throw new Zend_View_Exception('assign() expects a string or
array, got '.gettype($var));
}
}
public function escape($var)
{
if (is_string($var))
{
return parent::escape($var);
}
elseif (is_array($var))
{
foreach ($var as $key => $val)
{
$var[$key] = $this->escape($val);
}
return $var;
}
else
{
return $var;
}
}
public function output($name)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
print parent::render($name);
}
public function render($name)
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
print parent::render($name);
}
public function isCached($template)
{
if ($this->_smarty->is_cached($template))
{
return true;
}
return false;
}
public function setCaching($caching)
{
$this->_smarty->caching = $caching;
}
}
?>
in Controller for drawing using smarty i use:
$view->display('smarty_template.tpl')
and it works fine. But i want also to be able to use on the same $view
object
Zend render (so i could process php code), so i tried:
$view->render('zend_template.tpl.php')
But Zend returned:
Zend_View_Exception: script './application/views/zend_template.tpl.php' not
found in path in /usr/share/php/Zend/View/Abstract.php on line 571
Why ? How can i correct it ?
Thanx
--
View this message in context:
http://www.nabble.com/Smarty-integration-tf3260325s16154.html#a9061125
Sent from the Zend Framework mailing list archive at Nabble.com.
---------------------------------
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.