Routing, excess parameters, and 404

I have noticed, if you pass any extra parameter into the uri, a route would be performed even so. For example, controller 'Sign' has the action 'up' with no arguments; such links will do the same: exampe.com/sign/up/1 exampe.com/sign/up/2 exampe.com/sign/up/blablabla exampe.com/sign/up/blablabla/54g64w5y65y6fywf An unlimited amount of links are doing the same...

Now I'm trying to use some custom plugin with method's arguments checking by php5 reflections: if there is no argument but one has been placed into the uri then 404 is shown. But all this don't look flexible and handy.

Want to listen some suggestions from developers.



83.4k
edited Oct '14

By default Phalcon uses the following route to accept an arbitrary number of parameters:

'#^/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\.\_]+)(/.*)*$#'

You can replace it to limit the number of parameters:

'#^/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\.\_]+)(/.*){0,32}$#'
$router->add('#^/([a-zA-Z0-9\_]+)/([a-zA-Z0-9\.\_]+)(/.*){0,32}$#', array('controller' => 1, 'action' => 2, 'params' => 3));


21.5k

Thanks, but wanted something more dynamically. At least, to specify parameters inside the controller.

I thought about the annotations router. I could leave :contrller/:action part as is and check :params only which would be specified in action's annotation. And then check requested and required ones by plugin. But, as I read in other threads, annotations may slow perform. But what about the annotations meta-data? Does it be faster if store annotations meta-data into the memory?



83.4k

Actually, all the meta-data is stored in memory, using annotations is an option to manually define the meta-data rather than let phalcon instrospect it by reading the column information from the database information schema.

http://docs.phalconphp.com/en/latest/reference/models.html#models-meta-data