//$frontController->setControllerDirectory('./application/controllers');
//将原来的设置控制器目录改成以下方式:
$frontController->setControllerDirectory(array(
'default' => './application/controllers/',
'admin' => './application/controllers/admin/')
);
index.php
<?php
/**
* Bootstrap file
*/
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
set_include_path('.' . PATH_SEPARATOR . '../library/'
. PATH_SEPARATOR . './application/models'
. get_include_path());
require_once "Zend/Loader.php";
// autoload class
spl_autoload_register(array('Zend_Loader', 'autoload'));
// load configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
Zend_Registry::set('config', $config);
// setup database
$db = Zend_Db::factory($config->db->adapter, $config->db->config->asArray());
Zend_Db_Table::setDefaultAdapter($db);
// register the view we are going to use
$view = new Zend_View();
$view->setScriptPath('./application/views');
Zend_Registry::set('view', $view);
$auth = Zend_Auth::getInstance();
// setup controller
$baseUrl = substr($_SERVER['PHP_SELF'], 0,
strpos($_SERVER['PHP_SELF'], '/index.php'));
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl($baseUrl);
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(array(
'default' => './application/controllers/',
'admin' => './application/controllers/admin/')
);
// run!
$frontController->dispatch();
?>
default模块:
在application/controllers目录下的IndexController.php原来一样设计,不需要改动:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
}
public function otherAction()
{
}
}
?>
admin模块:
在application/controllers/admin目录下的IndexController.php是这样的。注意类名:admin_IndexController, 这符合目录-类名转换的约定。
<?php
class admin_IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
}
public function otherAction()
{
}
}
?>
好了,大功告成,就这么多。
访问的时候和原来是一样的。
http://localhost/ 访问默认模块index控制器indexAction() application/controllers/IndexController.php
http://localhost/admin 访问admin模块index控制器indexAction() application/controllers/admin/IndexController.php
没有评论:
发表评论