How to use optional parameters at zend routing

2019-06-04 23:32发布

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条回答
老娘就宠你
2楼-- · 2019-06-05 00:11

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.

查看更多
登录 后发表回答