Home > Backend Development > PHP Tutorial > 小弟我用ZF框整合smarty,出了点异常,请各位帮忙看上了

小弟我用ZF框整合smarty,出了点异常,请各位帮忙看上了

WBOY
Release: 2016-06-13 10:45:40
Original
782 people have browsed it

我用ZF框整合smarty,出了点错误,请各位帮忙看下了。
我用ZF框整合smarty,出了点错误,请各位帮忙看下了,貌似是路径的错误。
我先是在分别创建了application/views/templates和application/views/templates_c和application/views/templates_c/cache_c文件夹。
然后以插件形式。在index.php中加载Smarty。
    /*  
  * Date: 2009.8.16  
  * Author:DaGui  
  * Email:[email protected]  
  * QQ:308713166  
  */  
  error_reporting(E_ALL|E_STRICT);  
  date_default_timezone_set('Asia/Shanghai');  
  define('WEB_ROOT', 'http://192.168.12.190:81/vote/');  
  set_include_path('.' .PATH_SEPARATOR .'./library'.PATH_SEPARATOR.'./application/models/'.PATH_SEPARATOR . get_include_path());  
  require_once 'Zend/Loader.php';  
  Zend_Loader::registerAutoload();//设置Zend Framework 自动载入类文件  
  $registry = Zend_Registry::getInstance();  
   
  //配置数据库参数,并连接数据库  
  $config=new Zend_Config_Ini('./application/config/config.ini',null, true);  
  Zend_Registry::set('config',$config);  
  $dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());  
  $dbAdapter->query('SET NAMES UTF8');  
  Zend_Db_Table::setDefaultAdapter($dbAdapter);  
  Zend_Registry::set('dbAdapter',$dbAdapter);  
   
  //对smarty模版进行初始化  
  include 'Smarty/Smarty.class.php';  
  $views = new Smarty();  
  $views->left_delimiter = "{{";  
  $views->right_delimiter = "}}";  
  $views->compile_dir = 'application/views/templates_c';  
  $views->cache_dir = 'application/views/templates_c/cache_c';  
  $views->template_dir = 'application/views/templates';  
  function smarty_block_dynamic($param,$content,&$views)  
  {  
  return $content;  
  }  
  $views->register_block('dynamic','smarty_block_dynamic',false);  
  Zend_Registry::set('views', $views);  
   
  //创建验证对象  
  $auth = Zend_Auth::getInstance();  
  //创建访问权限对象  
  $acl = new Common_Plugin_MyAcl();  
   
  //设置控制器  
  $frontController =Zend_Controller_Front::getInstance();  
  $frontController->setBaseUrl('/vote')//设置基本路径  
  ->setParam('noViewRenderer', true)  
  ->registerPlugin(new Common_Plugin_MyAuth($auth, $acl))  
  ->registerPlugin(new Zend_Controller_Plugin_ErrorHandler())  
  ->setControllerDirectory('./application/controllers')  
  ->throwExceptions(true)  
  ->dispatch();  
?>


之后在控制器层我的代码如下:
class IndexController extends Zend_Controller_Action
{
  protected $views; /*模板对象*/
  protected $data; /*传递模版变量的对象*/
  function init()  
  {  
  $this->registry = Zend_Registry::getInstance();  
  $this->views = Zend_Registry::get('views');  
  $this->data = $this->_request->getBaseUrl();  
  }  
  
  public function smartyAction()
  {

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template