![]() |
|
|||
|
Cheers,
I banging my head against different objects for two days and i'm still far from getting the illumination (i am padawan level 1 in Zend Framework) especially in the bootstraping an application and its modules area. I would like to create an application withe the following structure: - application - configs [general app configs] - modules \-default \- controllers \- models \- views \-admin \- controllers \- models \- views Everything runs smoothly till i get to models, there is no way to call from a controller a model located in the same module without adding some code in the main bootstrap application file, though everything else runs perfectly (controllers and views). I made all kind of naughty tries from [PHP] $moduleLoader = new Zend_Application_Module_Autoloader(array( 'namespace' => '', 'basePath' => APPLICATION_PATH)); return $moduleLoader; [/PHP] I even add namespaces (default) etc. Please show some mercy and give a bit of help with some code. Last edited by BornForCode; 06-29-2009 at 10:32 PM. |
|
|||
|
A few things.
Firstly, the "default" module doesn't belong under the modules directory. The default module is the application itself and lives directly under application/ Add Code:
resources.modules = "" resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" Create modules/admin/Bootstrap.php and fill it with [php] <?php class Auth_Bootstrap extends Zend_Application_Module_Bootstrap { } [/php] to bootstrap the module, including setting up resource autoloaders for models, forms, services etc. Add this function [php] protected function _initAutoload() { new Zend_Application_Module_Autoloader(array( 'basePath' => APPLICATION_PATH, 'namespace' => 'Default', )); } [/php] to your application/Bootstrap.php to initialize the resource autoloaders for the default module. "Default" can be changed to whatever you are prefixing your resources (models, forms, services etc) of your default module with - often the application name. I've also blogged about turning the Guestbook application from the Quickstart guide into a module, there might be some more information there: Brenton Alker’s Deprecated Behaviour Building a Modular Application in Zend Framework – Part 2
__________________
Brenton Alker PHP Developer - Brisbane, Australia blog.tekerson.com | twitter.com/tekerson | brenton.mp |
|
|||
|
Hm, but why shouldn't reside the 'default' in the module area? To some point it has the same structure like any other module (controllers, models and views).
If you use a modular approach the zf tool creates all modules inside the modules folder but keeps the models folder outside. This behavior is hard to understand for me. I understand that in the models folder may reside all kind of tables that can be used general all over the application, but shouldn't this be made available from the modules/default/models to maintain the application architecture. Thank you for your comment, i succeeded to add the default module in the format i want just by adding this code in the application bootstrap file: [PHP] protected function _initAutoLoad() { $autoloader = new Zend_Application_Module_Autoloader( array( 'namespace' => 'Default', 'basePath' => APPLICATION_PATH . '/modules/default'), array( 'namespace' => 'Admin', 'basePath' => APPLICATION_PATH . '/modules/admin') ); return $autoloader; } [/PHP] I am not very proud with this code but for the moment it seems that this is the only one way to solve this. |
|
|||
|
Default module resources (controllers, models, views, etc.) should be placed outside modules directory, like Tekerson said. Idea is to make that default module and its resources some kind of global scope...
You shouldn't instantiate Zend_Application_Module_Autoloader for every module. Each module, in modules directory should have its own boostrap (Boostrap.php), which extends Zend_Application_Module_Bootstrap. In that case, if you put this line in your config file: resources.modules = "", an instance of Zend_Application_Module_Autoloader will be created by default for each discrete module, allowing you to autoload module resources. But if you still want to hold your default module in modules directory, its Boostrap class should extend Zend_Application_Module_Bootstrap, and then you have to tell front controller what module is default. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |