|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
chanti Smarty n00b
Joined: 27 Apr 2012 Posts: 3
|
Posted: Fri Apr 27, 2012 6:59 am Post subject: Facing issues while integrating smarty with zendframework |
|
|
This is my php class : i dont know where i am doing mistake.
<?php
class Templater extends Zend_View_Abstract
{
protected $_path;
protected $_engine;
public function __construct() {
$config = Zend_Registry::get('config');
require_once('Smarty/Smarty.class.php');
$this->_engine = new Smarty();
#this might b wrong
# $this->_engine->template_dir = $config->APPLICATION_PATH ->templates;
$this->_engine->template_dir = templates;
$this->_engine->compile_dir = sprintf('%s/APPLICATION_PATH/templates_c');
$this->_engine->plugins_dir = array(APPLICATION_PATH .'/include/Templater/plugins','plugins');
}
public function getEngine() {
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){
return $this->_engine->get_template_vars($key) !== null;
}
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->_engine->assign($spec, $value);
}
public function clearVars(){
$this->_engine->clear_all_assign();
}
public function render($name)
{
return $this->_engine->fetch(strtolower($name));
}
public function _run()
{ }
}
?>
This is my bootstrapfile:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Bootstrap Smarty view */
protected function _initView()
{
// initialize smarty view
$view = new Ext_View_Smarty($this->getOption('smarty'));
// setup viewRenderer with suffix and view
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setViewSuffix('tpl');
$viewRenderer->setView($view);
// ensure we have layout bootstraped
$this->bootstrap('layout');
// set the tpl suffix to layout also
$layout = Zend_Layout::getMvcInstance();
$layout->setViewSuffix('tpl');
return $view;
}
}
This is my controller :
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
require_once("smarty/libs/Smarty.class.php");
$article =array('smart1',
'smart2',
'smarty3');
$smarty=new Smarty();
$smarty->template_dir="'APPLICATION_PATH . '/views/templates";
$smarty->complile_dir="'APPLICATION_PATH . '/views/template_c";
$smarty->assign('news',$article);
$smarty->display('inex/index.tpl');
}
}
Plz help me i am new to smarty and zend frame work.
Thanks in advance. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
chanti Smarty n00b
Joined: 27 Apr 2012 Posts: 3
|
Posted: Fri Apr 27, 2012 7:52 am Post subject: |
|
|
yes ..i have tried that ..not working for me |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Apr 27, 2012 8:13 am Post subject: |
|
|
I see some wrong quoting here and you should use the Smarty3 setter methods when configuring the directories,
Code: | $smarty->template_dir="'APPLICATION_PATH . '/views/templates";
$smarty->complile_dir="'APPLICATION_PATH . '/views/template_c";
should be
$smarty->setTemplateDir=(APPLICATION_PATH . '/views/templates');
$smarty->setCompileDir=(APPLICATION_PATH . '/views/template_c');
|
|
|
Back to top |
|
chanti Smarty n00b
Joined: 27 Apr 2012 Posts: 3
|
Posted: Fri Apr 27, 2012 10:16 am Post subject: |
|
|
Thanks for your reply ..still facing the same problem,..some one please help |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|