zend framework 出错,该怎么解决

php中文网
发布: 2016-06-13 13:48:03
原创
997人浏览过

zend framework 出错,
用的是APACHE服务器,
在原理上在.htaccess设置 RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
就会把所有的请求发送到index.php,包括不存在的文件和目录

可是我只有在输入 http://localhost/zend/ 才能正访问,
如果输入 http://localhost/zend/ 和任意不存的目录或文件就会出错,出错信息如下:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
Fatal 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 code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php
    /*
     *
     *Zend Framework
     *
     */
    //require_once 'Zend/Controller/Front.php';
   // $rootPath = dirname(dirname(__FILE__));
    //Zend_Controller_Front::run($rootPath . '/z/application/controllers');
    
    error_Reporting(E_ALL|E_STRICT);
    date_default_timezone_set('asia/shanghai');

    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(); 
    $view = new Zend_View();
    $view->setScriptPath('./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-&gt;throwExceptions(true);// true 为抛出异常,false 为不抛出
            $frontCtrl-&gt;setParam('useDefaultControllerAlways', true); // true 为 404 总是重定向到默认控制器
            $this-&gt;_frontCtrl-&gt;registerPlugin(
                new Zend_Controller_Plugin_ErrorHandler(array('module'=&gt;'error', 'controller'=&gt;'error', 'action'=&gt;'error'))
            ); <div class="clear"></div>
登录后复制
相关标签:
php
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号