Bootstrap 函数 _initRouter() 破坏了我的自定义路由
我正在关注 从命令行运行 Zend Framework 操作
Fatal error: Zend_Controller_Router_Exception: Route logout is not defined
a> 并且我在 application.ini 中定义的自定义路线和导航
resources.router.routes.logout.route = logout
resources.router.routes.logout.defaults.controller = authentication
resources.router.routes.logout.defaults.action = logout
resources.navigation.pages.logout.label = "Logout"
resources.navigation.pages.logout.controller = "authentication"
resources.navigation.pages.logout.action = "logout"
resources.navigation.pages.logout.route = "logout"
resources.navigation.pages.logout.resource = "logout"
,因为我已将错误原因缩小到此引导函数:
protected function _initRouter ()
{
if (PHP_SAPI == 'cli') {
$this->bootstrap ('frontcontroller');
$front = $this->getResource('frontcontroller');
require_once APPLICATION_PATH. '/router/Cli.php';
$front->setRouter (new Application_Router_Cli ());
$front->setRequest (new Zend_Controller_Request_Simple ());
}
}
我在这里做错了什么?该错误仅在不使用 CLI 时出现(如果我删除 _initRouter(),它会按预期工作)。
I was following example 2 in Running a Zend Framework action from command line and I hit a fatal error
Fatal error: Zend_Controller_Router_Exception: Route logout is not defined
with a custom route and navigation which I define in application.ini as
resources.router.routes.logout.route = logout
resources.router.routes.logout.defaults.controller = authentication
resources.router.routes.logout.defaults.action = logout
resources.navigation.pages.logout.label = "Logout"
resources.navigation.pages.logout.controller = "authentication"
resources.navigation.pages.logout.action = "logout"
resources.navigation.pages.logout.route = "logout"
resources.navigation.pages.logout.resource = "logout"
I've narrowed the cause of the error down to this bootstrap function:
protected function _initRouter ()
{
if (PHP_SAPI == 'cli') {
$this->bootstrap ('frontcontroller');
$front = $this->getResource('frontcontroller');
require_once APPLICATION_PATH. '/router/Cli.php';
$front->setRouter (new Application_Router_Cli ());
$front->setRequest (new Zend_Controller_Request_Simple ());
}
}
What am I doing wrong here? The error is only present when not using CLI (and if I remove the _initRouter() it works as expected).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
application.ini 中的语法
resources.router
用于设置资源“router”。引导程序中存在名为“_initRouter()”的方法也会设置一个名为“路由器”的资源。我认为这种冲突是导致你的问题的原因,因为只有其中一个会运行(我不记得哪个优先)。我建议将您的方法重命名为
_initCliRouter()
之类的名称。The syntax
resources.router
in your application.ini is for setting up the resource "router". The existence of a method called "_initRouter()" in your bootstrap also setups up a resource called "router". I think this clash is what's causing your problem, as only one of these will be run (I can't remember which takes precedence).I'd suggest renaming your method to something like
_initCliRouter()
.