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

282 views Asked by At

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/value2/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?

3

There are 3 answers

0
Stoosh On

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

0
Phil On

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

0
BasTaller On

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.