如何在Zend路由上使用可选参数 [英] How to use optional parameters at zend routing

查看:87
本文介绍了如何在Zend路由上使用可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用可选参数为标准路由器设置类似的路由,例如:

I want to set a similar routing to the standard-router with optional parameters, e.g.:

intranet.route = 'intranet/:controller/:action/:title/:id'

仅id参数没有需要一个值。
i尝试给它提供一个 null 之类的默认值-但随后该变量仍被设置,但是当用户不给它任何值时,我根本不希望它存在

only the id-parameter doesn't need a value. i tried giving it an default value like null - but then the variable is still set, but i don't want it to exist at all when the user does not give it any value

另外,我该如何设置具有动态值的路由,就像这样:

also, how can i set up a route with dynamic values, just like this:

Intranet / index / index / Front%20Page / 123 / foo / bar

然后变量$ foo存在,值为 bar

then the variable $foo exists with the value "bar"

推荐答案

您可以为application.ini中的参数设置默认值,例如

you can set a default value to a parameter in application.ini like

resources.router.routes.intranet.defaults.id = null

或如果您想设置动态路由,可以使用*

or if you want to set a dynamic route you can use *

intranet.route = 'intranet/:controller/:action/:title/*

这使title之后的变量为可选。

this makes the variable after title optional.

这篇关于如何在Zend路由上使用可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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