Zend 路由不工作

发布于 2024-12-11 15:49:41 字数 605 浏览 2 评论 0 原文

我正在尝试使用 paths.ini 和 bootstrap 设置我的 zend 路由,但由于某种原因它无法按预期路由。我的routes.ini和bootstrap.php如下。

路线.ini

[production]
routes.guestbook.route = "/guestbook"
routes.guestbook.defaults.controller = guestbook
routes.guestbook.defaults.action = index

bootstrap.php

protected function _initRoutes() 
{

// Get Front Controller Instance

$front = Zend_Controller_Front::getInstance();

// Get Router
$router = $front->getRouter();

$router->addConfig(new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini', 'production'), 'routes');

}

I am trying to set up my zend route using the routes.ini and bootstrap but for some reason it is not able to route as expected. My routes.ini and bootstrap.php are as follows.

routes.ini

[production]
routes.guestbook.route = "/guestbook"
routes.guestbook.defaults.controller = guestbook
routes.guestbook.defaults.action = index

bootstrap.php

protected function _initRoutes() 
{

// Get Front Controller Instance

$front = Zend_Controller_Front::getInstance();

// Get Router
$router = $front->getRouter();

$router->addConfig(new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini', 'production'), 'routes');

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不奢求什么 2024-12-18 15:49:42

配置路由的最简单方法是使用 Zend_Application_Resource_Router

配置位于您的 application.ini 文件中,仅此而已,无需进一步的代码。

由于您似乎使用的是静态路由(无可变路径组件),请在 application.ini 文件中尝试此操作

resources.router.routes.guestbook.type = "Zend_Controller_Router_Route_Static"
resources.router.routes.guestbook.route = "guestbook"
resources.router.routes.guestbook.defaults.module = "default"
resources.router.routes.guestbook.defaults.controller = "guestbook"
resources.router.routes.guestbook.defaults.action = "index"

中删除 _initRoutes() 方法Bootstrap 类。


另外,这只是一个旁白,但是当在引导 _init* 方法中使用其他资源(例如前端控制器)时,您必须确保它们已正确引导。为此,请像这样检索它们

protected function _initSomething()
{
    // make sure resource is bootstrapped
    $this->bootstrap('frontController');

    // retrieve resource
    $front = $this->getResource('frontController');
}

请参阅 http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking

The easiest way to configure routing is by using the Zend_Application_Resource_Router.

Configuration goes in your application.ini file and that's it, no further code required.

As it appears you're using a static route (no variable path components), try this in your application.ini file

resources.router.routes.guestbook.type = "Zend_Controller_Router_Route_Static"
resources.router.routes.guestbook.route = "guestbook"
resources.router.routes.guestbook.defaults.module = "default"
resources.router.routes.guestbook.defaults.controller = "guestbook"
resources.router.routes.guestbook.defaults.action = "index"

Remove the _initRoutes() method from your Bootstrap class.


Also, this is just an aside but when using other resources such as the front controller in a bootstrap _init* method, you must ensure they've been properly bootstrapped. To do so, retrieve them like this

protected function _initSomething()
{
    // make sure resource is bootstrapped
    $this->bootstrap('frontController');

    // retrieve resource
    $front = $this->getResource('frontController');
}

See http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking

旧街凉风 2024-12-18 15:49:41

在阅读您的评论后,我可以断言您可以删除这些语句(配置和引导),因为您想要实现的是 zend 框架默认路由器的正常行为,除非您使用模块。

感谢 FloydThreepwood 记得我写下了这个细节。

After I've read your comment, I can assert that you can delete those statements (config and bootstrap) because what you want to achieve is the normal behavior of the zend framework default router unless you're using modules.

Thanks to FloydThreepwood who remeber me to write this detail.

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