Zend路由,抛出未找到的资源 [英] Zend routing, throws resource not found

查看:88
本文介绍了Zend路由,抛出未找到的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网址: http://dev.local/foodies/view?id = bluedaniel

和ive进入了我的引导程序:

and ive got in my bootstrap:

protected function _initRoute() {
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'production');
        $router = new Zend_Controller_Router_Rewrite();
        $router->addConfig($config, 'resources');
    }


ive也在我的route.ini中:

and ive also got in my routes.ini:

[production]
resources.router.routes.foodies_view.route = ":foodies/:id"
resources.router.routes.foodies_view.defaults.module = "foodies"
resources.router.routes.foodies_view.defaults.controller = "view"
resources.router.routes.foodies_view.defaults.action = "index"

所以 http://dev.local/foodies/bluedaniel 应该正常工作吗?

我得到了一个资源'foodies:bluedaniel'

I get a Resource 'foodies:bluedaniel' not found error however with this setup

---------------更新-------- -------

我将以下内容添加到application.ini文件中:

Instead of the above I added the following to the application.ini file:

resources.router.routes.myroute.route = "foodies/:id"
resources.router.routes.myroute.defaults.module = "foodies"
resources.router.routes.myroute.defaults.controller = "view"
resources.router.routes.myroute.defaults.action = "index"
resources.router.routes.myroute.defaults.id = "\w+"

该方法现在可以使用,尽管如果可以的话,我仍然希望它们单独的ini文件中的路由

This method now works although I would still prefer the routes in their seperate ini file if I can help it.

推荐答案

如果有人感兴趣,我已经解决了这个问题,现在在我的引导程序中:

If anyone is interested, I have solved the problem, now in my bootstrap:

protected function _initRoutes() {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addRoute('userprofile', new Zend_Controller_Router_Route('user/:id/', array('module' => 'foodies', 'controller' => 'view', 'action' => 'index', 'id'=>'\w+')));
}

问题是在我的navigation.xml中,我需要添加< route>默认< / route> 。 Zend文档有时确实非常非常糟糕。

The problem was that in my navigation.xml I needed to add <route>default</route> to every node. Zend documentation can be very very poor indeed at times.

我还需要为id声明一个默认变量,否则它将无法识别它已被传递。

I also needed to declare a default variable for id otherwise it wouldnt recognise it being passed.

这篇关于Zend路由,抛出未找到的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆