CodeIgniter Forums

Full Version: codeigniter 3.0-dev - routes urls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi guys,

I using CI 2.1.3, my system work fine... with HMVC
I have a admin painel, where there is a search form that final url is variable... as: -> home -> pagination -> text = search query 1, search query 2, etc ...

working fine...

but.. I started test with CI 3.0-dev ... using same base routes and modules.. etc
So, the routes work... but, I cant using ilimited search querys like above...
Return 404 -> home - OK
but... -> pagination -> text = search query 1, search query 2, etc ...
dont work because roles in route not specific with all blocks "/"

routes.php example : working fine in 2.1.3 for my projects::
$route['([a-zA-Z_-]+)/([a-zA-Z_-]+)/(:any)'] = "$2/$1/$3";

In resume, my idea in url are: controller/module/function / parameter1 / parameter2 / etc....

So, any idea why stopped work in 3.0-dev ?

El Forum

I replaced system/application/core/Router.php with 2.1.3 version and work fine now... why? Are there bugs !?

El Forum

I founded the bug::::

protected function _parse_routes()

// Convert wild-cards to RegEx
// original 3.0 - bugged
// $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key);

// original 2.1.3 - working
$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));

El Forum

File a bug report on github or it probably won't be noticed or looked at.

El Forum

Actually, your fix is the "bug".

There's information on this in the user guide for 3.0-dev - I'll go ahead and copy/paste it here though.


Historically, CodeIgniter has always provided the :any wildcard in routing,
with the intention of providing a way to match any character within an URI segment.

However, the :any wildcard is actually just an alias for a regular expression
and used to be executed in that manner as .+. This is considered a bug, as it
also matches the / (forward slash) character, which is the URI segment delimiter
and that was never the intention. In CodeIgniter 3, the :any wildcard will now
represent [^/]+, so that it will not match a forward slash.

There are certainly many developers that have utilized this bug as an actual feature.
If you're one of them and want to match a forward slash, please use the .+
regular expression::

(.+) // matches ANYTHING
(:any) // matches any character, except for '/'