CodeIgniter Forums
URI routing to give impression of directories - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: URI routing to give impression of directories (/thread-33192.html)



URI routing to give impression of directories - El Forum - 08-18-2010

[eluser]vishok[/eluser]
how can i do to give impression of directories for a controller without using routes.php.


URI routing to give impression of directories - El Forum - 08-18-2010

[eluser]minerbog[/eluser]
Sorry :|

Little confused here? What do you mean?

Can you give us more details of actually what you want to do?


URI routing to give impression of directories - El Forum - 08-18-2010

[eluser]vishok[/eluser]
i'm working on a cms based on codeigniter. I make a controller named 'page' and in it a function named 'index'. In my routes.php i write this $route['en/([\\w.-]*)'] = "page/index/en/$1". So every time i wrote something like this http://mysite.com/en/hotel_eden in address bar of my browser codeigniter call the controller 'page' and the function 'index'. By uri segment i take the rest to call the right view and show it. Now i would like to assign dynamically a category to my page. es. i'd like to have something like this http://mysite.com/en/hotel/hotel_eden and get the same page. Is it possible?


URI routing to give impression of directories - El Forum - 08-18-2010

[eluser]mddd[/eluser]
If your page name is only going to be in the last piece of the url, you could just make your route like this:
Code:
$route['en/(.*)([^/]+)'] = 'page/index/en/$2';
This will 'throw away' anything between 'en' and the last part of the uri.
So en/hotel_eden will go to page/index/en/hotel_eden.
But en/hotels/hotel_eden will also go to page/index/en/hotel_eden.
And en/a/b/c/d/hotel_eden will also go to page/index/en/hotel_eden.

The downside is, of course, that the 'folder name' does not do anything. So you couldn't have a page en/hotels/list and a page en/restaurants/list because both would go to 'list'.