Welcome Guest, Not a member yet? Register   Sign In
Regex routing problem
#1

[eluser]csernik.marton[/eluser]
Hi!

I've just started using CI a couple days ago for a new project, but I'm having a problem with regex routing. I've inserted a new route into routes.php:

Code:
$route['kategorije/([a-z0-9-_]+)'] = "categories/index/id/$1";

This should take reroute urls like 'domain.com/kategorije/test' to 'domain.com/categories/index/id/test' which is not working. I tried instead:

Code:
$route['kategorije/(:any)'] = "categories/index/id/$1";
and
Code:
$route['kategorije/:any'] = "categories/index/id/$1";

but none of these work correctly; basically, the variable "id" is not available on the page.
Thenafter I changed the route to this:

Code:
$route['kategorije/index/id/([a-z0-9-_]+)'] = "categories/index/id/$1";

and it suddenly works, but of course only for url 'domain.com/kategorije/index/id/test' which is not what I need.
For quick solution, I added this line to .htaccess, it works like a charm this way, but obviously this is not the most beautiful way to solve the problem Smile

Code:
RewriteRule kategorije/([a-z0-9-_]+)/?$ categories/index/id/$1 [L]

Do you have ideas? I use CI 1.7.2.

Regards!
#2

[eluser]BrianDHall[/eluser]
Hm, odd indeed. First, I'd turn on profiling: http://ellislab.com/codeigniter/user-gui...iling.html

Then visit various parts of your site and ensure the uri information submitted makes sense. Sometimes having the wrong uri protocol can cause behaviors similar to this.
#3

[eluser]csernik.marton[/eluser]
I've turned it in, but everything seems to be absolutely fine (or I'm the one who doesn't know what to look at Smile)
#4

[eluser]Colin Williams[/eluser]
You say you aren't getting the id, but are you in fact getting to the Categories controller's index() function?

If you are, then routing is working fine. Be aware that the ID value would be available at either $this->uri->segment(2) or $this->uri->rsegment(4);
#5

[eluser]csernik.marton[/eluser]
You're absolutely right. But in this case, I have uri->uri_to_assoc() turned on, there's no way to get the variable with his 'name', only with uri->®segment?




Theme © iAndrew 2016 - Forum software by © MyBB