zend framework 出错,
用的是apache服务器,
在原理上在.htaccess设置 rewriterule !\.(js|ico|gif|jpg|png|css)$ index.php
就会把所有的请求发送到index.php,包括不存在的文件和目录
可是我只有在输入 http://localhost/zend/ 才能正访问,
如果输入 http://localhost/zend/ 和任意不存的目录或文件就会出错,出错信息如下:
php codefatal error: uncaught exception 'zend_controller_dispatcher_exception' with message 'invalid controller specified (error)' in c:\php\library\zend\controller\dispatcher\standard.php:241 stack trace: #0 c:\php\library\zend\controller\front.php(934): zend_controller_dispatcher_standard->dispatch(object(zend_controller_request_http), object(zend_controller_response_http)) #1 g:\web\php\z\index.php(36): zend_controller_front->dispatch() #2 {main} thrown in c:\php\library\zend\controller\dispatcher\standard.php on line 241
我的index.php是这样写的
php codesetscriptpath('./application/views/scripts/index/');//设置模板显示路径 $registry['view'] = $view;//注册view //配置数据库参数,并连接数据库 $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); //设置控制器 $frontcontroller =zend_controller_front::getinstance(); $frontcontroller->setbaseurl('/z')//设置基本路径 ->setparam('noviewrenderer', true) ->setcontrollerdirectory('./application/controllers') ->throwexceptions(false) ->dispatch();
------解决方案--------------------
你需要在创建 frontcontroller 的时候设置
php code $frontctrl->throwexceptions(true);// true 为抛出异常,false 为不抛出 $frontctrl->setparam('usedefaultcontrolleralways', true); // true 为 404 总是重定向到默认控制器 $this->_frontctrl->registerplugin( new zend_controller_plugin_errorhandler(array('module'=>'error', 'controller'=>'error', 'action'=>'error')) );