:int removes last character form generated route

Hello all,

when I use the following pattern "/view/:int/info" in a route and I create a url for it via the url helper, the following result is produced: "/view/4/inf".

As you can see, the last character is removed.

Using "/view/([0-9]+)/info" produces "/view/4/info". Is this a normal behaviour or is it a bug?


The replacement for :int is /([0-9]+), it also includes the first slash, https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/router/route.zep#L124


Okay, but how is :int used correctly? Why it can't be used in a pattern like "/view/:int/info"?

I'm using the latest Phalcon 1.3.3 compiled from GitHub source code. The important lines here: https://github.com/phalcon/cphalcon/blob/master/ext/mvc/router/route.c#L300

edited Dec '15

I would like to bump this up, as unless this problem has been fixed in > 2.0.7 it most likely still exists.

The problem originates in the \Phalcon\Mvc\Url::get function. When the reverse routing happens, the pattern is cut short by 1 char when :int is used. So, for example for route "/view/:int/print" gets replaced as "/view/4/prin" as the op has presented.

The bigger problem is when you have a second regex condition in the route e.g. "/view/:int/(notes|history)". The use of ":int" breaks the regex and it can't fill in the option when using "$url->get(array('for'=>'view-specific', 'id'=>4, 'display'=>'notes'))". The uri generated is "/view/4/". When defining the route, if "([0-9]+)" is used instead of ":int", the output is "/view/4/notes" as expected.

So, the current solution seems to be to use the regex instead of ":int", but :int is nice and it would be good if fixed!

Sample route: [code] $group->add('/view/:int/(notes|history)', array( 'controller' => 'index', 'action' => 'testview', 'id' => 1, 'display' => 2 ))->setName('testview'); [/code] [code] Sample URI reverse route call $this->uri->get(array( 'for' => 'testview', 'id' => 4, 'display' => 'notes' )); [/code]