![]() |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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';
}
}
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/ |
|
|||
|
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 |
|
|||
|
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 02: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: 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! |
![]() |
| Tags |
| config, setup, zend framework 1.9 zendvn |
| 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 |
![]() |