Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Setup multi modules in Zend Framework v1.9 with 13 steps

  1. #1
    www.zend.vn is offline 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/

  2. #2
    tjorriemorrie is offline Member
    Join Date
    Mar 2009
    Posts
    68

    Default

    I have the following in my application.ini:
    Code:
    resources.modules[] = ""
    What's the difference of the []?

  3. #3
    bsdfgsaga is offline 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

  4. #4
    w0land is offline 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...

  5. #5
    Neantis is offline 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?

  6. #6
    risoknop is offline 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.

  7. #7
    PHPop is offline 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 01:17 PM.

  8. #8
    slartibartfast is offline 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 Attached Images

  9. #9
    Dwarth is offline Junior Member
    Join Date
    Mar 2009
    Location
    Montreal, QC, Canada
    Posts
    2

    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!

  10. #10
    MCB Web Design is offline Junior Member
    Join Date
    Jan 2012
    Posts
    1

    Default

    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

Page 1 of 2 12 LastLast

Similar Threads

  1. How can I design for multi-products with multi-properties?
    By jazz4u in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 01-27-2010, 12:29 PM
  2. zend-Magento CE Setup - can't get it to work
    By notknow in forum Installation & Configuration
    Replies: 4
    Last Post: 01-23-2010, 12:14 AM
  3. Zend Framework 1.9 modules lazy loading
    By getout in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 11-25-2009, 03:41 AM
  4. Handling different steps in a single module
    By aneevs in forum Concepts, Ideas, Planning
    Replies: 1
    Last Post: 07-02-2008, 05:07 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •