Yet another way would be to extend your action controller, so that it has method for locating and loading the module (as generally models are needed within actions). Here is small article on how to do this: ZF: models auto-loading.
hi guys,
here is the way I handle this issue :
1) add the models foldes to include path :
[PHP]// add ZF Home and models folders to include_path
$includePath = array(
'/opt/ZendFramework/1.6/library/' ,
'../library' ,
'../application/common/models/' ,
'../application/forum/models/' ,
'../application/admin/models/' ,
'.' ,
get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $includePath));[/PHP]
2) register an autoload function
a] under windows
[PHP]spl_autoload_register();[/PHP]
By doing this, spl_autoload() will be automatically registered as autoloader, and will look for {$classname}.php and {$classname}.inc in every directory listed in include path.
b] under GNU/Linux
You may paid attention to the {$classname} instead of {$className}? If yes, you already understood why it is necessary to create a home made autoloader function for Linux : spl_autoload() lowercase the class name when it looks for the source file. So, when there is no problem with Windows (whose filesystem is case insensitive), using this trick under Linux would lead you to break the file naming convention of ZF. To avoid this horrible crime, just add this code somewhere in/from your bootstrap :
[PHP]function modelAutoloader($className) {
require_once "$className.php";
}
spl_autoload_register('modelAutoLoader');
[/PHP]
Last edited by gauthier; 09-05-2008 at 03:30 PM.
Yet another way would be to extend your action controller, so that it has method for locating and loading the module (as generally models are needed within actions). Here is small article on how to do this: ZF: models auto-loading.