Rewrite url vs Controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Rewrite url vs Controller (/showthread.php?tid=42159) |
Rewrite url vs Controller - El Forum - 05-27-2011 [eluser]stingray9[/eluser] Hi, i got a little question, let me explain my problem. I made it possible for a costumer on my application to create three pages. They can give the page a title and content. Every page is saved in the database under page1, page2 and page3. Now, my controller is extra, with functions: page1, page2 and page3. So the url they see is basic_url/extra/page1 But it would be more nice, if the url was the title they have set up their-self (saved in the database) and not that ugly extra/page1. The problem is referring to my correct controller by then. I hope i explained it well and someone have a possible solution for me. Rewrite url vs Controller - El Forum - 05-27-2011 [eluser]theprodigy[/eluser] Take a look at CodeIgniter's routing Rewrite url vs Controller - El Forum - 05-28-2011 [eluser]stingray9[/eluser] [quote author="theprodigy" date="1306555012"]Take a look at CodeIgniter's routing[/quote] Thanks for answering. So you believe it's possible to write some php code in that route config file? As i don't know the titles, they are saved in the database. Rewrite url vs Controller - El Forum - 05-28-2011 [eluser]osci[/eluser] You define only route there and then you can remap in your controller User Guide - Remap for example Code: public function _remap($method, $params = array()) but you should probably make page1, page2, page3 one function ie page since the serve the same purpose (display a title and a content) and the you would have Code: return call_user_func_array(array($this, 'page'), $params); btw the title should be translated to safe url (no spaces or disallowed characters), maybe saving it at db while updating record title so you can query against that. Rewrite url vs Controller - El Forum - 05-28-2011 [eluser]stingray9[/eluser] Thanks mate, _remap() did the trick for me. Your post really helped me out! Rewrite url vs Controller - El Forum - 05-29-2011 [eluser]osci[/eluser] I kind of love _remap() |