Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > General Q&A on Zend Framework

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-28-2009, 06:16 PM
Junior Member
 
Join Date: May 2009
Posts: 13
Question [Solved] Boostraping modules, models and all the fun

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-29-2009, 03:40 AM
Senior Member
 
Join Date: Jul 2008
Posts: 288
Default

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"
to appliction.ini to initialize the module resource plugin and set the modules directory.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-29-2009, 07:14 AM
Junior Member
 
Join Date: May 2009
Posts: 13
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-29-2009, 10:14 AM
Senior Member
 
Join Date: Apr 2009
Posts: 151
Default

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.
__________________
My site | My profile | Webfolio CMS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 03:00 AM.


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