How to set resource which is not mapped
The dir structure is:
application
models
Milestones
ObserverBroker.php => Application_Model_Milestone_ObserverBroker
Observers
Milestone.php => Application_Model_Observer_Milestone
at Bootstrap.php
$loader->addResourceType('observer','models/observers','Mo开发者_JAVA技巧del_Observer');
$loader->addResourceType('observerbroker','models/milestones','Model_Milestone');
The problem I encountered was:
[f@gail]$ php zfrun.php \
> --environment development -a task.create-milestone -m '%s' \
> -p '%s'
PHP Fatal error: Class 'Application_Model_Milestone_ObserverBroker' not found in /var/www/html/sites/plugin_handler/application/controllers/TaskController.php on line 55
Fatal error: Class 'Application_Model_Milestone_ObserverBroker' not found in /var/www/html/sites/plugin_handler/application/controllers/TaskController.php on line 55
[f@gail]$ php zfrun.php \
> --environment development -a task.update-milestone -m '%s' -o '%s' \
> -p '%s'
PHP Fatal error: Class 'Application_Model_Milestone_ObserverBroker' not found in /var/www/html/sites/plugin_handler/application/controllers/TaskController.php on line 81
You shouldn't have to add a resource type for classes in the Application_Model_
namespace.
The default module autoloader already includes rules for this, provided your configured appnamespace
is "Application"
As a test, I just created two models, Application_Model_Test
(application/models/Test.php) and Application_Model_Test_Test
(application/models/Test/Test.php) and without adding anything further, was able to create an instance of each in my controller.
Edit
On re-reading your question, it looks like you want to store the Application_Model_Milestone_
classes in "Milestone*s*" (plural) and likewise for the Observer classes. Whilst I think you would be better off just storing these under application/models/Milestone
and application/models/Observer
and letting the default autoloader do its thing, it looks like your problem is due to case sensitivity.
Your $loader->addResourceType()
calls are using lowercase folder names whereas your directory structure example uses Milestones
and Observers
(capital first letters).
This will fail on a case-sensitive filesystem.
精彩评论