Hello people,
I'm still new to ZF, but i was trying to implement ZF with smarty with help of this site:
http://framework.zend.com/manual/en/...w.scripts.html
But i have a problem.
Here's the folder structure:
Here are some files for reference:Code:/application /controllers /models /Smarty /cache /config /templates /templates_c /library /Smarty -- holds smarty files /Zend -- holds zf files .htaccess index.php -- bootstrapper file
smarty.php
indexController.phpPHP Code:<?php
require_once '../library/Smarty/libs/Smarty.class.php';
class Zend_View_Smarty implements Zend_View_Interface
{
/**
* Smarty object
* @var Smarty
* @return void
*/
protected $_smarty;
/**
* Constructor
*
* @param $tmplPath
* @param $extraParams
* @return void
*/
public function __construct($tmplPath = null, $extraParams = array())
{
require_once '../library/Smarty/libs/Smarty.class.php';
$this->_smarty = new Smarty;
if(null !== $tmplPath)
{
$this->setScriptPath($tmplPath);
}
foreach ($extraParams as $key=>$value)
{
$this->_smarty->$key = $value;
}
}
/**
* Return the template engine object
*
* @return Smarty
* @see library/Zend/View/Zend_View_Interface#getEngine()
*/
public function getEngine()
{
return $this->_smarty;
}
/**
* Set path to templates
*
* @param string $path
* return void
* @see library/Zend/View/Zend_View_Interface#setScriptPath()
*/
public function setScriptPath($path)
{
if (is_readable($path))
{
//Sets all smarty directories
//$this->_smarty->template_dir = $path;
$this->_smarty->template_dir = $path . '/templates';
$this->_smarty->compile_dir = $path . '/templates_c';
$this->_smarty->cache_dir = $path . '/cache';
$this->_smarty->config_dir = $path . '/config';
get_class_methods('Smarty');
return;
}
throw new Exception('Invalid path provided');
}
/**
* retrieve all current template directories
*
* @return string
* @see library/Zend/View/Zend_View_Interface#getScriptPaths()
*/
public function getScriptPaths()
{
return $this->_smarty->template_dir;
}
/**
* alias for setScriptPath
*
* @param string $path
* @param string prefix unused
* @return void
* @see library/Zend/View/Zend_View_Interface#setBasePath()
*/
public function setBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}
/**
* Alias for setScriptPath
*
* @param string $path
* @param string $prefix Unused
* @return void
*/
public function addBasePath($path, $prefix = 'Zend_View')
{
return $this->setScriptPath($path);
}
/**
* Assign variable to the template
*
* @param string $key The variable name.
* @param mixed $val The variable value.
* @return void
* @see library/Zend/View/Zend_View_Interface#__set()
*/
public function __set($key, $val)
{
$this->_smarty->assign($key, $val);
}
/**
*
* @param $key
* @return unknown_type
*/
public function __get($key)
{
return $this->_smarty->get_template_vars($key);
}
/**
* Allows testing with empty() and isset() to work
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return (null !== $this->_smarty->get_template_vars($key));
}
/**
* Allows unset() on object properties to work
*
* @param string $key
* @return void
*/
public function __unset($key)
{
$this->_smarty->clear_assign($key);
}
/**
* Assign variables to the template
*
* Allows setting a specific key to the specified value, OR passing
* an array of key => value pairs to set en masse.
*
* @see __set()
* @param string|array $spec The assignment strategy to use (key or
* array of key => value pairs)
* @param mixed $value (Optional) If assigning a named variable,
* use this as the value.
* @return void
*/
public function assign($spec, $value = null)
{
if (is_array($spec)) {
$this->_smarty->assign($spec);
return;
}
$this->_smarty->assign($spec, $value);
}
/**
* Clear all assigned variables
*
* Clears all variables assigned to Zend_View either via
* {@link assign()} or property overloading
* ({@link __get()}/{@link __set()}).
*
* @return void
*/
public function clearVars()
{
$this->_smarty->clear_all_assign();
}
/**
* Processes a template and returns the output.
*
* @param string $name The template to process.
* @return string The output.
*/
public function render($name)
{
return $this->_smarty->fetch($name);
}
}
?>
index.tplPHP Code:<?php
class indexController extends Zend_Controller_Action
{
public function init()
{
// Set Smarty defaults so it is availale throught the class
$this->view = new Zend_View_Smarty();
$this->view->setScriptPath(realpath('../application/Smarty'));
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($this->view);
$viewRenderer->setViewBasePathSpec('../application/Smarty/templates');
$viewRenderer->setViewScriptPathSpec(':controller/:action.:suffix');
$viewRenderer->setViewScriptPathNoControllerSpec(':action.:suffix');
$viewRenderer->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}
function indexAction()
{
$this->view->author = 'Zoran';
}
}
Now it seems to be ok, but i have a problem, as it seems that it cannot find .tpl files, but it does not display any error, it's just blank site (but it did load smarty class and all that).PHP Code:<html>
<head>
<title>BRAVO</title>
</head>
<body>
<h1>{$author}</h1> BLA
</body>
</html>
SO any ideas where i went wrong? Tnx.





Bookmarks