Zend 路由不工作
我正在尝试使用 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');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
配置路由的最简单方法是使用
Zend_Application_Resource_Router
。配置位于您的
application.ini
文件中,仅此而已,无需进一步的代码。由于您似乎使用的是静态路由(无可变路径组件),请在
application.ini
文件中尝试此操作从
中删除
_initRoutes()
方法Bootstrap 类。另外,这只是一个旁白,但是当在引导
_init*
方法中使用其他资源(例如前端控制器)时,您必须确保它们已正确引导。为此,请像这样检索它们请参阅 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
fileRemove the
_initRoutes()
method from yourBootstrap
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 thisSee http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking
在阅读您的评论后,我可以断言您可以删除这些语句(配置和引导),因为您想要实现的是 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.