I have the following in my application.ini:
What's the difference of the []?Code:resources.modules[] = ""
Easy to setup multi modules in Zend Framework with 13 steps (tutorial)
1. Create basic structure for the application
(H001)
2. Create detail structure for each module (Admin & Default)
(H002)
3. Configure file application\index.php
Code:<?php date_default_timezone_set('Asia/Ho_Chi_Minh'); // Define base path obtainable throughout the whole application defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__))); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', BASE_PATH . '/application'); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development')); set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), APPLICATION_PATH . '/modules/admin/models' , get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap()->run();
4. Configure file application\.htaccess
Code:RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
5. Setup application file which contain configuration of application application\configs\application.ini
Code:[production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.modules = "" resources.layout.layout = "layout" resources.layout.layoutpath = APPLICATION_PATH "/layouts" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
6. Create content for file application\layouts\ layout.phtml
Code:<?php echo $this->doctype(); ?> <html> <head> <?php echo $this->headMeta(); ?> <?php echo $this->headTitle(); ?> <?php echo $this->headLink(); ?> </head> <body> <?php echo $this->layout()->content; ?> </body> </html>
7. Create content for bootstrap file of appliction application\ Bootstrap.php
Code:<?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { }
Setup configration for Admin module (Back-End) (View picture H002)
8. Create content for bootstrap file of Admin module application\modules\admin\Bootstrap.php
Code:<?php class Admin_Bootstrap extends Zend_Application_Module_Bootstrap { }
9. Enter content into IndexController của Admin module - application\modules\admin\controllers\IndexControl ler.php
Code:<?php class Admin_IndexController extends Zend_Controller_Action { public function indexAction(){ $this->view->show = 'Zend Framework training course in www.zend.vn<br>Back-End'; } }
10. Show content indexAction in IndexController of Admin module - application\modules\admin\views\scripts\index\inde x.phtml
Code:<h2><?php echo $this->show;?></h2>
Setup configration for Default module (Front-End) (view picture H002)
11. Create content for bootstrap file of Default module application\modules\default\Bootstrap.php
Code:<?php class Default_Bootstrap extends Zend_Application_Module_Bootstrap { }
12. Enter content into IndexController của Default module - application\modules\default\controllers\IndexContr oller.php
13. Show content indexAction in IndexController of Default module - application\modules\default\views\scripts\index\ index.phtmlCode:<?php class IndexController extends Zend_Controller_Action { public function indexAction(){ $this->view->show = 'Zend Framework training course in www.zend.vn<br>Front-End'; } }
Code:<h2><?php echo $this->show;?></h2>
Run:
Front-End: http://localhost/multi-module/ Or http://localhost/multi-module/index
Back-End: http://localhost//multi-module/admin/
I have the following in my application.ini:
What's the difference of the []?Code:resources.modules[] = ""
OK, cool!^_^ I just wanted to make sure I didn't do anything wrong :]
Nice! I'll start saving up some scratch for this
__________________
Organisme de credit a la consommation | Organisme maison de credit immobilier | Organisme de rachat de credit en ligne
Really, the first one to sort out this mystery.
It looks like there must be a subclass of Zend_Application_Module_Bootstrap at the module level...
I guess the application bootstrap file is called and then the module bootstrap is, am I right? Is it possible to share models, forms, etc... between the modules? How zf handles this?
Why are there two bootstrap files (one for each module)? Is there any reason for that? I always use just one bootstrap file in my modular Zend Framework applications.
1. Setting resources.modules[] = "" instead of resources.modules = "", causes the resources[modules] to have an element [0].
2. Yes, the module bootstraps are called after the main one. It's generally to setup module specific initialization which makes portability a little easier.
3. You can share models using autoloader after the dispatch process is called in your plugins. Otherwise you'd have to load and call the models the old school way.
Cheers
Last edited by PHPop; 01-17-2010 at 01:17 PM.
Thanks to ZVN - Vietname Zend Framework - Open Source Group for this great tutorial.
I followed it step by step to fit my own application.
But I now I have the trouble that my application loads infinitly.
My config looks like the following:
My for my application structure see attachment.Code:[production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" appnamespace = "Application" resources.frontController.controllerDirectory = APPLICATION_PATH "/modules/frontend/controllers" resources.frontController.params.displayExceptions = 0 resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" ;resources.frontController.plugins[] = "Plugin_LayoutAsign" resources.modules[] = resources.layout.layout = "layout" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" resources.view[] = resources.db.adapter = "pdo_mysql" resources.db.params.host = "localhost" resources.db.params.username = "root" resources.db.params.password = "" resources.db.params.dbname = "webhostinges" resources.db.params.charset = "utf8" resources.db.isDefaultTableAdapter = true
Has someone an idea whats going wrong ?
Thanks in advance
I have a weird issue;
When I run the "$application->bootstrap();" function in the index.php file, bootstrap of all my modules are run no matter the module I'm in.
/admin/ AND /index
will load:
application\Bootstrap.php
application\modules\default\Bootstrap.php
application\modules\admin\Bootstrap.php
I believe tat with a lot of modules the application will start to run slower!
This didn't work for me. I get the following error when trying to view any URL:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /usr/share/ZendFrameworkCli/library/Zend/Controller/Dispatcher/Standard.php:248 Stack trace: #0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /usr/share/ZendFrameworkCli/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 /usr/share/ZendFrameworkCli/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #3 /Users/Martin/Dropbox/Repositories/realestatecms/public/index.php(26): Zend_Application->run() #4 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)#0 /usr/share/ZendFrameworkCli/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) in /usr/share/ZendFrameworkCli/library/Zend/Controller/Plugin/Broker.php on line 336