在我的第一个zend应用程序中出错

时间:2012-01-10 13:27:02

标签: zend-framework

你好我的第一个使用Zend Framework的应用程序我跟着 tutorial完成后我得到了以下错误它非常好而且很简单。请告诉我为什么我会得到这个?

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\xampp\htdocs\zend_login\library\Zend\Controller\Dispatcher\Standard.php:248

Stack trace:
#0 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#2 C:\xampp\htdocs\zend_login\web_root\index.php(9): Zend_Controller_Front::run('/application/co...')
#3 {main}

Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)
#0 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#2 C:\xampp\htdocs\ in C:\xampp\htdocs\zend_login\library\Zend\Controller\Plugin\Broker.php on line 336

这是我在web_root文件夹中的index.php

 <?php
 error_reporting(E_ALL|E_STRICT);
 ini_set('display_errors', true);
 date_default_timezone_set('Europe/London');
 $rootDir = dirname(dirname(__FILE__));
 set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());
 $rootDir . '/library' . PATH_SEPARATOR . get_include_path();
 require_once 'Zend/Controller/Front.php';
 Zend_Controller_Front::run('/application/controllers');
 ?>

1 个答案:

答案 0 :(得分:3)

您已配置Zend的错误处理程序,但没有错误处理程序控制器。你真正的问题应该在于此背后。

使用以下内容在controllers目录中创建一个ErrorController.php文件:

class ErrorController extends Zend_Controller_Action
{
    /**
     * Handles system errors and 404s
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $priority = Zend_Log::NOTICE;
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $priority = Zend_Log::CRIT;
                $this->view->message = 'Application error';
                break;
        }

        // Log exception, if logger available
        if ($log = $this->getLog()) {
            $log->log($this->view->message, $priority, $errors->exception);
            $log->log('Request Parameters', $priority, $errors->request->getParams());
        }

        // conditionally display exceptions
        if ($this->getInvokeArg('displayExceptions') == true) {
            $this->view->exception = $errors->exception;
        }

        $this->view->request   = $errors->request;
    }

    /**
     * Get the log
     * 
     * @return Zend_Log|false
     */
    public function getLog()
    {
        $bootstrap = $this->getInvokeArg('bootstrap');
        if (!$bootstrap->hasResource('Log')) {
            return false;
        }
        $log = $bootstrap->getResource('Log');
        return $log;
    }
}

相应的视图/错误/ error.phtml:

<h2><?php echo $this->message ?></h2>

<?php if (isset($this->exception)): ?>

<h3>Exception information:</h3>
<p>
  <b>Message:</b> <?php echo $this->exception->getMessage() ?>
</p>

<h3>Stack trace:</h3>
<pre><?php echo $this->exception->getTraceAsString() ?></pre>

<h3>Request Parameters:</h3>
<pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?></pre>

这或多或少是Zend Framework脚本在创建新项目时创建的默认值(由于我目前没有干净的版本而且没有时间创建新项目,因此它们稍作修改 - 但它应该的工作。)

您可以在此处阅读有关错误处理程序的更多信息:http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler