zend framework 出錯,該怎麼解決

來源:互聯網
上載者:User
zend framework 出錯,
用的是APACHE伺服器,
在原理上在.htaccess設定 RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
就會把所有的請求發送到index.php,包括不存在的檔案和目錄

可是我只有在輸入 http://localhost/zend/ 才能正訪問,
如果輸入 http://localhost/zend/ 和任意不存的目錄或檔案就會出錯,出錯資訊如下:
PHP code
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
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->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'))            ); 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.