Php – Uncaught exception ‘Zend_Controller_Dispatcher_Exception’ error when using Zend framework

PHPzend-framework

Im using the Zend Framework v1.11.0 on a Windows machine running the Xampp 1.7.1 package.My project directory structure is as follows.

/
|- /data
| |- /logs
| |- /uploaded-files
| |- /tmp
|- /htdocs
|- /include
| |- /Controllers
| |- /Zend
|- /templates

I have the following code in my index.php located in htdocs :

<?php

    require_once('Zend/Loader.php');
    Zend_Loader::registerAutoload();

    $controller = Zend_Controller_Front::getInstance();
    $controller->setControllerDirectory('../include/Controllers');
    $controller->dispatch();

?>  

The error i get is as follows :

Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in C:\xampp\htdocs\myproject\include\Zend\Loader.php on line 266

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

#0 C:\xampp\htdocs\myproject\include\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))

#1 C:\xampp\htdocs\myproject\htdocs\index.php(8): Zend_Controller_Front->dispatch()

#2 {main} thrown in C:\xampp\htdocs\myproject\include\Zend\Controller\Dispatcher\Standard.php on line 248

My .htaccess file located in myproject/htdocs :

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

In my apache httpd.conf i have the following VirtualHost defined:

<VirtualHost myproject:80>
    ServerName myproject
    DocumentRoot "c:/xampp/htdocs/myproject/htdocs"
    <Directory "c:/xampp/htdocs/myproject/htdocs">
        AllowOverride None
        Options All
    </Directory>
    php_value include_path ".;c:/xampp/htdocs/myproject/include;c:/xampp/php/PEAR"
    php_value magic_quotes_gpc off
    php_value register_globals off
</VirtualHost>

What could be going wrong here ?

Please Help
Thank You

Best Answer

first of all ;

Zend_Loader::registerAutoload();

is deprecated and that why you get the first notice

Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in C:\xampp\htdocs\myproject\include\Zend\Loader.php on line 266

in your case your application doesn't know what is default controller name and its default ac tion it throw an error and the error handler take the its place and again your front controller tried to locate the error controller and it doesn't find it as well so it show you this error

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

okay last : how do i fix if i would be in charge :

1- re-mange the application structure to be like the default ZF file structure 2- you can try to set the default controller name and action name , consult the docs or navigate to Zend/Controller/Front.php and you would find functions like

public function setDefaultAction($action)
    {
        $dispatcher = $this->getDispatcher();
        $dispatcher->setDefaultAction($action);
        return $this;
    }

 public function setDefaultAction($action)
    {
        $dispatcher = $this->getDispatcher();
        $dispatcher->setDefaultAction($action);
        return $this;
    }

and many other setters functions

and don't forget to take a deep look @ ZF flowchart http://devzone.zend.com/article/4601

i hope that help you