Bootstrap 函数 _initRouter() 破坏了我的自定义路由

发布于 2024-12-04 19:17:09 字数 1273 浏览 1 评论 0原文

我正在关注 从命令行运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-12-11 19:17:09

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文