Main Content RSS FeedArticles Entry

zend framework

PHP的zend framework框架,需要在Apache中启用mod_rewrite功能.

初次使用时一直提示错误真的是很郁闷.

我的网站结构为:

www (网站根目录)

|-/data

|-/include

  |-/Zend

  |-/controllers

根目录下放:index.php 和 .htaccess

.htaccess 代码如下

代码如下
  1. RewriteEngine on
  2. RewriteCond %{SCRIPT_FILENAME} !-f
  3. RewriteCond %{SCRIPT_FILENAME} !-d
  4. RewriteRule ^(.*)$ index.php/$1


index.php 代码如下

代码如下
  1. <?php
  2. set_include_path('./include' . PATH_SEPARATOR . get_include_path());
  3. require_once('zend/Loader.php');
  4.  
  5. Zend_Loader::registerAutoload();
  6.  
  7. $controller=Zend_Controller_Front::getInstance();
  8. $controller->setControllerDirectory('./include/Controllers');
  9. $controller->dispatch();
  10. ?>


然后在controllers建立 IndexController.php 文件

IndexController.php 代码如下


代码如下
  1. <php
  2. class IndexController extends CustomControllerAction
  3. {
  4. public function indexAction()
  5. {
  6. echo '这里是首页';
  7. die();
  8. }
  9. }
  10. ?>



这样运行后一直提示这个错误:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in E:wwwincludeZendControllerDispatcherStandard.php:241 Stack trace: #0 C:phplibraryZendControllerFront.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 E:wwwindex.php(36): Zend_Controller_Front->dispatch() #2 {main} thrown in E:wwwincludeZendControllerDispatcherStandard.php on line 241

 

 


最后才知道是没有 View
看了下书,因为我要用的是Smarty模板 所以自己建立 Templater这个类
在index.php 中加入:

代码如下
  1. // Templater
  2. $vr = new Zend_Controller_Action_Helper_ViewRenderer();
  3. $vr->setView(new Templater());
  4. $vr->setViewSuffix('html');
  5. Zend_Controller_Action_HelperBroker::addHelper($vr);



从而解决这个错误. 记得需要先安装Smarty,Templater中的代码有些多,而且是抄书上的 我就不贴上来了.