How to use optional parameters at zend routing

寵の児 提交于 2019-12-08 03:56:39

问题


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

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

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

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


回答1:


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/*

this makes the variable after title optional.



来源:https://stackoverflow.com/questions/11966188/how-to-use-optional-parameters-at-zend-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!