ホームページ  >  記事  >  バックエンド開発  >  Zend フレームワーク エラー、解決方法

Zend フレームワーク エラー、解決方法

WBOY
WBOYオリジナル
2016-06-13 13:48:03832ブラウズ

Zend フレームワーク エラー、
は APACHE サーバーを使用しています。
は原則として、.htaccess! に RewriteRule を設定します。(js|ico|gif|jpg|png|css)$index.php
はすべてのリクエストを配置します存在しないファイルやディレクトリも含めて、index.php に送信されます

ただし、http://localhost/zend/ と入力した場合にのみアクセスできます。
http://localhost/ と入力した場合zend / 存在しないディレクトリまたはファイルはエラーを引き起こします。エラーメッセージは次のとおりです。

PHP コード
<!--

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 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コード
を設定する必要があります
            $frontCtrl->throwExceptions(true);// true は例外をスローすることを意味し、false は例外をスローしないことを意味します
            $frontCtrl->setParam('useDefaultControllerAlways', true); // 404 の場合は常にデフォルトのコントローラーにリダイレクトされます。
            $this->_frontCtrl->registerPlugin(
                new Zend_Controller_Plugin_ErrorHandler(array('モジュール'=>'エラー', 'コントローラ'=>'エラー', 'アクション'=>'エラー'))
            );<div class="clear"></div>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。