Search code examples
phpzend-frameworkfatal-errorinclude-path

Fatal error: Class 'Zend_Controller_Action' not found


I've found some answers that are closely related to this problem, but I still can't get it resolved. I believe folks are saying that something is not correct with my include path, but I've tried all resolutions I could find to no avail.

Here's the error:

Fatal error: Class 'Zend_Controller_Action' not found in /Users/*me*/Sites/*site*/application/controllers/IndexController.php on line 3

Here's the include statements:

$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = 'include';
$newIncludePath[] = get_include_path();
$newIncludePath[] = '../library';
$newIncludePath[] = '../application/classes/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/controllers';
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);

require_once 'Zend/Controller/Front.php';
require_once 'Zend/Loader.php';

Zend_Loader::registerAutoload();

I have been banging my head on the keyboard for hours scouring the forums. I'm new to zend and php. This stuff has given me a royal headache. I've explicitly added controllers into the path. I have no idea what I am overlooking.

btw, the me and site are redacted names for privacy reasons.

I am eternally grateful for a resolution.

mjs-edit:

I noticed my includes were a bit wonky. So here's a do-over:

$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = get_include_path();
$newIncludePath[] = '../library';
$newIncludePath[] = '../application/classes/';
$newIncludePath[] = '../application/models/';
$newIncludePath[] = '../application/library/';
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);

The output of var_dump:

string(148) "../application/controllers:.:.:/Applications/MAMP/bin/php5/lib/php:../library:../application/classes/:../application/models/:../application/library/"

I noticed that Zend/Controller/Action exists under ../library. So, I don't understand why the app can't find it.

If I run IndexController from PHPDebug, it returns

string(170) ".:/Users/me/Sites/site:/Applications/Zend/Zend Studio - 7.1.0/plugins/org.zend.php.framework.resource_7.1.0.v20091101-1523/resources/ZendFramework-1/library/" 
Fatal error: Class 'Zend_Controller_Action' not found in /Users/me/Sites/site/application/controllers/IndexController.php on line 5

Solution

  • The default behavior of a Zend_Appilcation autoloader is to take the class name

    Zend_Controller_Action
    

    and convert it into a path

    Zend/Controller/Action.php
    

    and then attempt to include/require the needed file to load the class.

    So, you could have two different things going wrong

    1. Your PHP include path isn't pointing to the default Zend library folder, and attempts to include Zend/Controller/Action.php are failing.

    2. The autoloader isn't registered correctly

    So, in your IndexController.php file, add the following in the global namespace area above the class declaration

    var_dump(get_include_path());
    

    This will output your include path value. Check each individual path in your include path, and ensure that appending Zend/Controller/Action.php to one of them resolves to the Action.php file. If it doesn't, take steps to ensure that a path IS there that allows this to happen.

    (the above assumes you're using a Zend_Application, which Zend's own application framework based on their own Zend Framework. If you're using the components stand-alone there could be further complications)