Creating Dynamic Pages - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Creating Dynamic Pages (/showthread.php?tid=38968) |
Creating Dynamic Pages - El Forum - 02-24-2011 [eluser]barisv[/eluser] Hi, I am dynamically creating links that will refer news are added by admin. The news are added to the database as id, title and its content. And I am showing the list of news on any view by using related table on db. The news are shown like list of item by their title. For instance; Code: <a href="http://localhost/page/news/this-is-a-news/1">this is a news</a> If I can get id of the news from url, I can dynamically create the page but I couldnt reach it because it says 404 page not found as I expect also. How can I design the system to solve this issue ? I suppose that it waits for methods after Code: http://localhost/page/news/ I know that I can reach url segment as below, but I didnt get how to use it for this problem. Code: $id = $this->uri->segment(5); Thanks in advance. Creating Dynamic Pages - El Forum - 02-24-2011 [eluser]ramm[/eluser] I'm guessing you have a controller named "page.php" which contains a method called "news($id)". If thisd is correct, you can try doing something like: Code: //within your page.php controller And then call your url http://localhost/page/news/something/xx You should get "xx", if you don't, there something else wrong with your site configuration. Creating Dynamic Pages - El Forum - 02-24-2011 [eluser]barisv[/eluser] page is my root folder. news is my controller. How can I pass id to the controller from url ? Because after I click the link (http://localhost/page/news/this-is-a-news/1), it says "page not found". I doesnt run index function of news controller. Creating Dynamic Pages - El Forum - 02-24-2011 [eluser]ramm[/eluser] Because you don't have a method called "this-is-news" in your "news" controller. Remember CI by default will look for base_url/controller/method/parameters unless we change that. What i did in a case like that, was this: In the config/routes.php file Code: $route['news/:any'] = "news/article/$1"; And then in your controller Code: function article($id) As you can see it here http://ellislab.com/codeigniter/user-guide/general/routing.html Creating Dynamic Pages - El Forum - 02-24-2011 [eluser]InsiteFX[/eluser] Correct way! You can match literal values or you can use two wildcard types: (:num) will match a segment containing only numbers. (:any) will match a segment containing any character. InsiteFX Creating Dynamic Pages - El Forum - 02-25-2011 [eluser]barisv[/eluser] This is exactly what I needed. It works now. Thank you very much. |