1
votes

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

3
why you don't use the regular index.php file that comes with zend tooltawfekov

3 Answers

2
votes

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

1
votes

The message Invalid controller specified (error), means that the dispatcher is looking for a controller class named ErrorController but cannot find it.

The ErrorController is usually called when the throwExceptions flag is set to false in Zend_Controller_Front. When that is the case, thrown exceptions will be aggregated and forwarded to the ErrorController class. This is a feature supplied by the ErrorHandler plugin: a class named Zend_Controller_Plugin_ErrorHandler.

In short, there is probably something in your code that is throwing an exception, but since you don't have an error controller, the dispatcher fails. Changing the throwExceptions flag in the front controller, creating the error controller, or disabling the plugin should allow you to see where the actual error is coming from.

0
votes

I know this is too late, this may be useful for some one else who encountered this error like me.

For first error: replace this code.

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

with this one

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

and change your directory structure a bit and use following code make a file IndexController.php in index folder

$controller = Zend_Controller_Front::getInstance();
$controller->setDefaultModule('index');
$controller->addModuleDirectory('PATH_TO_MODULES')->dispatch();

instead of using this

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

your director structure look like this

application
   modules
       index
          controllers
              IndexController.php
          views