问题
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