addResourceType - how can I add Models_Mapper as a resource?
I'm writing a PHP application using PHP 5.3 and Zend Framework 1.11.7.
I created model resource using the following command:
protected function _initLoader()
{
$loader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default',
'basePath' => APPLICATION_PATH,
));
$loader -> ad开发者_JAVA百科dResourceType ( 'model', 'models', 'Model');
}
now whenever i use a class name that starts with Default_Model_
it goes and searches in models directory. under models directory i have a directory called mapper.
how can I configure that whenever a class is being used that starts with Default_Model_Mapper_
to auto-load it from models/mapper ?
ZF should find any directory under models automatically. Also you shouldn't need to include the default module either.
Model_
Model_Mapper_
Also to setup ZF modules I have the following 2 lines of code in my application.ini file
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
And the following in my bootstrap
protected function _initModuleAutoload()
{
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/default'));
return $modelLoader;
}
I hope this is of some help
Kind regards
Garry
Add this one:
$loader->addResourceType('mapper', 'models/mapper', 'Model_Mapper_');
The order in which you declare the two resource types might matter. So try it both ways; one of them should work.
It is set by default in Zend_Application_Module_Autoloader in initDefaultResourceTypes:
$this->addResourceTypes(array(
'dbtable' => array(
'namespace' => 'Model_DbTable',
'path' => 'models/DbTable',
),
'mappers' => array(
'namespace' => 'Model_Mapper',
'path' => 'models/mappers',
),
'form' => array(
'namespace' => 'Form',
'path' => 'forms',
),
....
精彩评论