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/