Welcome Guest, Not a member yet? Register   Sign In
Controller URL's
#1

[eluser]devvee[/eluser]
Hi!

When calling a controller in CodeIgniter the second URI segment is used to call a function inside that controller. Is it possible to replace that with a random segment that doesnt have a matching function?

For instance if I have the controller "Page", calling it from localhost would mean I'd browse to http://localhost/page/. In the page controller I have 2 functions: "add" and "delete". If I want to delete a page with a certian ID, I currently go to http://localhost/page/delete/1 to delete the page with ID 1.

Now what I'd like is being able to do http://localhost/page/1 to view the page with the ID 1, while not having the second segment filled would display a list of all pages. The only other way I know is to make a view function and go to http://localhost/page/view/1.


My second question.. I visited the codeigniter wiki which has a rather interesting URL. As an example: http://codeigniter.com/wiki/Category:Ima...and_Cache/

Is it possible to do this with CodeIgniter without heavy modifications? If so.. how?

Thanks in advance!
#2

[eluser]Phil Sturgeon[/eluser]
1.) URI Routing

2.) Edit your application/config/config.php and add in the extra characters to $config['allowed_characters']. This will let them exist in the URL without throwing an error. To get it to pick things up, look into routing, _remap() or extending the Router class. Not an easy one.




Theme © iAndrew 2016 - Forum software by © MyBB