开发者

Zend Framework: Can I set a depth for url parameters?

I would like to get only one parameter. For example site.ru/controller/action/param1/value/

But if I request follow url: site.ru/controller/action/param1/value/param2/v开发者_C百科alue2/param3/value4/ by default I havn't any error.

Is it possible to set up the depth for url parameters? Or I shuld do it manually via url parsing?


The default route allows any number of parameters after the :module/:controller/:action (or just :controller/:action) parts.

If you want to limit this, create your own route.

See http://framework.zend.com/manual/en/zend.controller.router.html


By default, there is no limit on the amount of param => value pairs used in the URL.

However you can create your own custom routes if you want to restrict the URL parameters


Consider this code:

$route = new Zend_Controller_Router_Route(
            '/:controller/:action/:id',
            array('controller'=>'index','action'=>'index','id'=>''), //default values
            array('controller'=>'[a-zA-Z-]','action'=>'[a-zA-Z-]+','id'=>'([0-9]+)') //patterns to match values
);

This route will be triggered only if request consists of controller name, action name and number for id. If any other parameters will be passed, route won't be triggered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜