views:

999

answers:

2

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
A: 

Your include paths are relative to the application root but the file is being loaded at a different level (ie. application/controllers). So, all include paths now look like application/controllers/../library which is incorrect.

I would fix this by using absolute paths in my include path. For example, try changing ../library to Users/me/Sites/site/library

Brad
Or you could use `realpath(dirname(__FILE__)."/../library")` to not tie yourself to a particular host.
gnarf
I've tried all suggestions without success. Where does the include path get set initially? I ask because "../application/controllers:" is the first entry which is retrieved from "get_include_path()". And PHP Debug reports that zend_controller_action is not found there. Maybe something is wrong in an ini file somewhere?
Mike
A: 

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)

Alan Storm