Routing doesn't work |
[eluser]Marty[/eluser]
Hi, I have problem with URI routing in CI. I've read many topics about this, but still can't solve my problem. I have very simple app - one controller that shows some articles - its name is "homepage" and it is set as default controller. In this controller I have index function that show homepage site. Another function is called "show" and this function shows articels due to 3. uri segment, for example: www.example.com/homepage/show/my_article, where "my_article" is identificator for database. I have removed index.php from my URI shcema. So, now I need to route URI, when I use www.example.com/my_article I want to call www.example.com/homepage/show/my_article My code is: Code: $route['my_article'] = "homepage/show/my_article"; but it doesn't work (I allways get only index) and I really don't know where is the problem... I've tried Code: $route[':any'] = "homepage/show/$1"; I am using Code Igniter Version 2.0.2 Can someone, please, tell me, what I am doing wrong? Thx all.
[eluser]pickupman[/eluser]
Routing runs until it finds a match. So you will need to define some other routes above the :any, otherwise only that will be run. Route override the default URI loading method. Code: $route['homepage'] = 'homepage/index';
[eluser]Marty[/eluser]
Thx, I've tried both code, you posted, but it still doesn't work. Is it possible, that it could be server side problem? (htaccess or something else)
[eluser]pickupman[/eluser]
Doesn't work doesn't help us figure put the problem. Are you getting an error or still just getting the same page served. You could post you. htaccess file to if there is something going wrong there.
[eluser]Marty[/eluser]
Yeah, I'm sorry. I always get only index function of "homepage" controller, that is set as default. My htaccess file: Code: <IfModule mod_rewrite.c>
[eluser]pickupman[/eluser]
Just try something vanilla like this one. Code: RewriteEngine On Sometimes depending on the server environment, it's picky about having the question mark following index.php.
[eluser]Marty[/eluser]
Thx, I changed htaccess to this, but still the same situation as before...
[eluser]pickupman[/eluser]
Make sure you have both routes I posted before. Code: $route['homepage'] = 'homepage/index'; Also, could you post code from your controller, as maybe it something from there. Or try creating a test controller, and see what happens when you try and access it. Maybe your /homepage/show method shows the hompage/index if the slug (article name) is not found?
[eluser]John_Betong_002[/eluser]
>>> but it doesn’t work (I allways get only index) Try inserting this script and post the output. Code: class homepage { |
Welcome Guest, Not a member yet? Register Sign In |