0
votes

Using PHP 5.3 and Zend Framework 1.11.7 I've been trying to configure the AutoLoader to auto load my Model classes (for Zend_Db) that resides in the default directory application/models.

I found the following solution:

I can add the following function to the Bootstrap.php:

protected function _initLoader() 
{
    $loader = new Zend_Loader_Autoloader_Resource (array (
    'basePath' => APPLICATION_PATH,
    'namespace' => 'Default'));
    $loader -> addResourceType ( 'model', 'models', 'Model'); 
}  

it seems like an option that should be easily set in application.ini. so my question is, are there any relevant directives that I can add to application.ini that perform the same task my function performs ?

update

after setting the appnamespace directive, i still need to add the following function:

protected function _initLoader() 
{    
    $loader = new Zend_Loader_Autoloader_Resource (array (
    'basePath' => APPLICATION_PATH));
    $loader -> addResourceType ( 'model', 'models', 'Model'); 
}

or else it won't find my model classes.

the only difference is that I removed the attribute 'namespace'.

any other attributes i can add to remove this function entirely ?

thank you! :)

Kfir

2

2 Answers

1
votes

In your application.ini you should have set

appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

The appnamespace is the prefix you use for your models so if your model is "Default_Model_User" then the appnamespace will be 'Default', if your model is "Application_Model_User" then the appnamespace will be "application"

These two directives should sort out your autoloading for the default application

You can also set it in your bootstrap with, you need to use the Zend_Application_Module_AutoLoader:

protected function _initDefaultModuleAutoloader()
{
    $this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Application',
        'basePath'  => APPLICATION_PATH,
    ));
}
1
votes

Put the following in your application.ini

appnamespace = "MyNamespace"

Then it will load a file in your application/models directory with a class named MyNamespace_Model_MyModel.