Hi,
I've been using Zend with my projects since 0.7 and using a Smarty class
with the View to allow me to $this->view->render using the templates.
I've upgraded to Zend 1.0.0 and all my pages broke with a fatal error
message
*Fatal error*: Class Foo_View_Smarty contains 3 abstract methods and must
therefore be declared abstract or implement the remaining methods
(Zend_View_Interface::getScriptPaths, Zend_View_Interface::setBasePath,
Zend_View_Interface::addBasePath)
The class code is listed bellow but after searching for a while I saw some
posts regarding the ViewRenderer. Since I'll have to recode some files I am
looking for a 'definitive' way to integrate Smarty with Zend without having
to wait until Zend_Layout appears...
class Foo_View_Smarty implements Zend_View_Interface
{
protected $_smarty;
public function __construct($path = null, array $config = array())
{
$this->_smarty = new Smarty;
if ($path !== null)
{
$this->setScriptPath($path);
}
foreach ($config as $key => $value)
{
$this->_smarty->$key = $value; }
}
public function getEngine()
{ return $this->_smarty;
}
public function setScriptPath($path)
{ if (!Zend_Loader::isReadable($path))
{ throw new Zend_View_Exception("Unable to read script
path: {$path}"); }
$this->_smarty->template_dir = $path;
}
public function __set($key, $value)
{ $this->_smarty->assign($key, $value);
}
public function __get($key)
{
return $this->_smarty->get_template_vars($key);
}
public function __isset($key)
{
return $this->_smarty->get_template_vars($key) !== null;
}
public function __unset($key)
{
$this->_smarty->clear_assign($key);
}
public function assign($spec, $value = null)
{
if (is_array($spec))
{
$this->_smarty->assign($spec);
}
else
{
$this->_smarty->assign($spec, $value);
}
}
public function clearVars()
{
$this->_smarty->clear_all_assign();
}
public function render($name)
{
return $this->_smarty->fetch($name);
}
public function fetch($name)
{
return $this->_smarty->fetch($name);
}
}