我正在使我的bootstrap.php文件更有条理,但是在将所有内容放入单独的静态方法之后,我无法加载索引控制器之外的任何页面。例如。 如果我试着打开
http://localhost/zftutorial/login/index
我得到了
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message
'Invalid controller class ("Login_IndexController")' in C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php:341
Stack trace: #0 C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php(255):
Zend_Controller_Dispatcher_Standard->loadClass('IndexController') #1 C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Front.php(934):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http)) #2 C:\Program
Files\VertrigoServ\www\zftutorial\public\index.php(18): Zend_Controller_Front->dispatch()
#3 C:\Program Files\VertrigoServ\www\zftutorial\public\index.php(138): Bootstrap::run() #4
{main} thrown in C:\Program
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php on
line 341
在我的bootstrap文件中,我似乎已经定义了控制器的位置:
public static function setupFrontController()
{
self::$frontController = Zend_Controller_Front::getInstance();
self::$frontController->throwExceptions(true);
self::$frontController->returnResponse(true);
self::$frontController->setBaseUrl('/zftutorial');
self::$frontController->setControllerDirectory(
array(
'default' => self::$root . '../application/controllers',
'admin' => self::$root . '../application/controllers',
'index' => self::$root . '../application/controllers',
'login' => self::$root . '../application/controllers',
'user' => self::$root . '../application/controllers'
)
);
self::$frontController->setParam('registry', self::$registry);
}
也许它必须对路由做些什么,但我的应用程序在使用隐式路由之前工作正常,例如其他控制器也运行良好。什么是上述错误的来源?我该如何测试/找到/修复它?
答案 0 :(得分:0)
查看堆栈跟踪错误是无效的控制器类(“Login_IndexController”)
这表明类Login_IndexController不存在。
您应该在登录模块的控制器目录中有一个名为IndexController.php的文件。您目前的结构将无法工作,因为两个模块不能具有相同名称的控制器。将结构更改为
self::$frontController->setControllerDirectory(
array(
'default' => self::$root . '../application/modules/default/controllers',
'admin' => self::$root . '../application/modules/admin/controllers',
'index' => self::$root . '../application/modules/index/controllers',
'login' => self::$root . '../application/modules/login/controllers',
'user' => self::$root . '../application/modules/user/controllers'
)
);
在self :: $ root中创建IndexController.php。 '../application/modules/login/controllers并确保该类名为Login_IndexController