Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > Resources for Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-21-2009, 07:53 AM
Junior Member
 
Join Date: Nov 2009
Posts: 2
Default Setup multi modules in Zend Framework v1.9 with 13 steps

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
Code:
<?php
class IndexController extends Zend_Controller_Action {
   
   public function indexAction(){
      $this->view->show = 'Zend Framework training course in www.zend.vn<br>Front-End';
      
   }
}
13. Show content indexAction in IndexController of Default module - application\modules\default\views\scripts\index\ index.phtml
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/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-21-2009, 02:48 PM
Member
 
Join Date: Mar 2009
Posts: 67
Default

I have the following in my application.ini:
Code:
resources.modules[] = ""
What's the difference of the []?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-28-2009, 01:23 AM
Junior Member
 
Join Date: Nov 2009
Posts: 1
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-13-2009, 01:06 AM
Junior Member
 
Join Date: Dec 2009
Posts: 1
Thumbs up Very helpful, thx!

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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-24-2009, 01:54 PM
Junior Member
 
Join Date: Dec 2009
Posts: 3
Default

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-17-2010, 03:27 AM
Junior Member
 
Join Date: Jan 2009
Posts: 26
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-17-2010, 02:14 PM
Junior Member
 
Join Date: Jan 2010
Posts: 5
Default

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 02:17 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-05-2010, 12:47 PM
Junior Member
 
Join Date: Feb 2010
Posts: 4
Default

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:

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
My for my application structure see attachment.

Has someone an idea whats going wrong ?

Thanks in advance
Attached Images
File Type: jpg screen_tree.jpg (16.6 KB, 4 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-04-2010, 04:48 PM
Junior Member
 
Join Date: Mar 2009
Location: Montreal, QC, Canada
Posts: 1
Default

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
config, setup, zend framework 1.9 zendvn

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 02:50 PM.


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