Regular expression & routing problem |
[eluser]m4rw3r[/eluser]
Why not use: Code: $route['^([\d\w\-]+?)$'] = "test/blog/$1"; It does not match a "/", so if you enter "http://localhost/blogentry/comments", it will not match (but it will match "http://localhost/blogentry/" because CI removes all preceding and succeeding slashes). If you need more characters, add them to the character class (a good reference on regular expressions are http://www.regular-expressions.info/).
[eluser]Michael Ekoka[/eluser]
Hey Animas, I see a couple of inconsistencies in your code. 1- First, the route Code: $route['([a-z0-9-]+)'] = "blog/post/$1"; www.site.com/blog/post/post-title-a will be routed to blog/post/blog/post/post-title-a You probably want to test your route as www.site.com/post-title-a and www.site.com/post-title-b 2- The URI:egment() method In your Blog::post() action you have this line: Code: $this->db->where('title', $this->uri->segment(3)); To fetch your controller's method's arguments you don't wanna use the URI:egment() method. This is for prerouted url. You rather wanna use the post routed segment method: URI::rsegment(): Code: $this->db->where('title', $this->uri->rsegment(3)); Or better yet, these 2 alternative methods: - if you know the number of arguments that you will receive, declare it in the action method: Code: class Blog{ - if you don't want to specify the list of arguments in the declaration, use either of the php functions func_get_arg() or func_get_args(): Code: class Blog{
[eluser]Animas[/eluser]
Thanks m4rw3r. I used Code: $route['^([\d\w\-]+?)$'] = "blog/post/$1"; Now Ekoka. You pointed me to the magic word "rsegment". I didn't know it's use earlier. Now everything is working. Your help is much appreciated. And also thanks for taking the time to go through my code keenly. |
Welcome Guest, Not a member yet? Register Sign In |