现在的位置: 首页 > 综合 > 正文

Zend framework 多个Module时控制器名称

2012年02月18日 ⁄ 综合 ⁄ 共 1121字 ⁄ 字号 评论关闭

启动文件:index.php

<?php
set_include_path('.' . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
include_once "Zend/Loader.php";

Zend_Loader
::loadClass('Zend_Controller_Front');
$frontController = Zend_Controller_Front::getInstance(); 
$frontController->setParam('noViewRenderer', true);
$frontController->setControllerDirectory(
                                        
array(
                                            
'test'=>'app/test/controllers',
                                            
'default'=>'app/default/controllers'
                                            )
                                        );
$frontController->throwExceptions(true);
$frontController->dispatch();
?>

设定默认模块的控制器
class indexController extends Zend_Controller_Action{
    public function indexAction(){
        /*....*/
    }
}
没有问题

在设定test模块的控制器的时候
class indexController extends Zend_Controller_Action{
    public function indexAction(){
        echo 'this test controller test';
    }
会出现错误

正确形式为:
class Test_indexController extends Zend_Controller_Action{
    public function indexAction(){
        echo 'this test controller test';
    }
}

控制器命名必须是: "Module" + "_" + "Controller" + "Action"

抱歉!评论已关闭.