Fawad Ghafoor
Fawad Ghafoor

Reputation: 6207

Error in in my first zend app

hello all its my first application using Zend Framework i have followed tutorial it was very nice and simple after finishing i got the following error .anyone please tell me why i am getting this ??

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

this is my index.php in web_root folder

 <?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');
 ?>

Upvotes: 3

Views: 4600

Answers (1)

Hikaru-Shindo
Hikaru-Shindo

Reputation: 1901

You have configured the error handler of Zend but there is no error handler controller. Your real problem should lie behind this.

Create a file ErrorController.php inside of your controllers directory with the following contents:

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;
    }
}

And the corresponding view views/error/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>

This are more or less the defaults the Zend Framework scripts create on creation of a new project (They are modified a little since I do not have a clean version at the moment and no time to create a new project - But it should work.)

You may read more on the error handler here: http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler

Upvotes: 3

Related Questions