首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

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

2012-09-13 
我用ZF框整合smarty,出了点错误,请各位帮忙看下了。我用ZF框整合smarty,出了点错误,请各位帮忙看下了,貌似

我用ZF框整合smarty,出了点错误,请各位帮忙看下了。
我用ZF框整合smarty,出了点错误,请各位帮忙看下了,貌似是路径的错误。
我先是在分别创建了application/views/templates和application/views/templates_c和application/views/templates_c/cache_c文件夹。
然后以插件形式。在index.php中加载Smarty。
  <?php  
  /*  
  * Date: 2009.8.16  
  * Author:DaGui  
  * Email:daguizhang@gmail.com  
  * 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()
  {


  $show = "smarty";
  //显示模版
  $this->views->assign('show',$show);
  $this->views->display('smarty.phtml');
  }


  视图层的代码:{{$show}}


  我的zend树型格式是这样的:
 


我在网页里面查看的时候错如下:
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in D:\zend\public\index.php on line 12

Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='.;./library;./application/models/;.;C:\php5\pear') in D:\zend\public\index.php on line 12


请高手指点下了。谢了

[解决办法]
require_once(Zend/Loader.php)
表示需要把zend的library加到php.ini的include_path里面。
建议要绝对路径。

Zend_View集成Smarty模板系统
http://blog.csdn.net/mengxiangbaidu/article/details/7236249
[解决办法]
require_once('../library/Zend/Loader.php'); //这样试试。或者用绝对路径。

热点排行