I am using 1.10.2 and after reading the documentation(see The Module Resource Autoloader near the end). I thought that the autoloader would be able to find my models within each module by calling
Code:
$model = new Admin_Model_Event();
However this caused a class not found error.
For now I manually told it using a _init resource in the bootstrap:
Code:
$resourceLoader = new Zend_Loader_Autoloader_Resource( array(
'namespace' => '',
'basePath' => APPLICATION_PATH ));
$resourceLoader->addResourceType( 'model', 'modules/admin/models/', 'Model' );
$resourceLoader->addResourceType( 'dbtable', 'modules/admin/models/DbTable/', 'DbTable' );
This is not an elegant solution as I would have to manually list an equivalent for every module.
Just to be sure I dumped the autoloader
Code:
<?php
class Admin_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$loader = Zend_Loader_Autoloader::getInstance();
die( print_r( $loader->getAutoloaders() ));
}
}
and received:
Code:
Array
(
[0] => Zend_Loader_Autoloader_Resource Object
(
[_basePath:protected] => /...../intranet/webapp/application
[_components:protected] => Array
(
[Model] => /...../intranet/webapp/application/modules/admin/models
[DbTable] => /...../intranet/webapp/application/modules/admin/models/DbTable
)
[_defaultResourceType:protected] =>
[_namespace:protected] =>
[_resourceTypes:protected] => Array
(
[model] => Array
(
[namespace] => Model
[path] => /...../intranet/webapp/application/modules/admin/models
)
[dbtable] => Array
(
[namespace] => DbTable
[path] => /...../intranet/webapp/application/modules/admin/models/DbTable
)
)
)
[1] => Zend_Application_Module_Autoloader Object
(
[_basePath:protected] => /...../intranet/webapp/application
[_components:protected] => Array
(
[Model_DbTable] => /...../intranet/webapp/application/models/DbTable
[Model_Mapper] => /...../intranet/webapp/application/models/mappers
[Form] => /...../intranet/webapp/application/forms
[Model] => /...../intranet/webapp/application/models
[Plugin] => /...../intranet/webapp/application/plugins
[Service] => /...../intranet/webapp/application/services
[View_Helper] => /...../intranet/webapp/application/views/helpers
[View_Filter] => /...../intranet/webapp/application/views/filters
)
[_defaultResourceType:protected] => model
[_namespace:protected] =>
[_resourceTypes:protected] => Array
(
[dbtable] => Array
(
[namespace] => Model_DbTable
[path] => /...../intranet/webapp/application/models/DbTable
)
[mappers] => Array
(
[namespace] => Model_Mapper
[path] => /...../intranet/webapp/application/models/mappers
)
[form] => Array
(
[namespace] => Form
[path] => /...../intranet/webapp/application/forms
)
[model] => Array
(
[namespace] => Model
[path] => /...../intranet/webapp/application/models
)
[plugin] => Array
(
[namespace] => Plugin
[path] => /...../intranet/webapp/application/plugins
)
[service] => Array
(
[namespace] => Service
[path] => /...../intranet/webapp/application/services
)
[viewhelper] => Array
(
[namespace] => View_Helper
[path] => /...../intranet/webapp/application/views/helpers
)
[viewfilter] => Array
(
[namespace] => View_Filter
[path] => /...../intranet/webapp/application/views/filters
)
)
)
)
I am sure there is a simple way to inform Zend it needs to look inside the "modules" folder for it's resource mappings not just the "application" folder.
Look forward to getting over this issue.
Thank you for your help.