![]() |
display id and title in url Codeigniter - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: display id and title in url Codeigniter (/showthread.php?tid=58742) Pages:
1
2
|
display id and title in url Codeigniter - El Forum - 07-14-2013 [eluser]johanriyan[/eluser] hello guys, i am newbie in codeigniter. i have problem in url, i want display id and title in url like this : www.example.com/articel/12345/example-news help me please. thks. display id and title in url Codeigniter - El Forum - 07-14-2013 [eluser]JoostV[/eluser] Code: $id = 12345; display id and title in url Codeigniter - El Forum - 07-14-2013 [eluser]johanriyan[/eluser] Hello joostv, thks for respone. but i have route like this : Code: $route['news/(:any)'] = 'news/view/$1'; i am try not work. my controller : Code: public function index() This is view : Code: <?php foreach ($news as $news_item): ?> and i am try using your code : Code: <?php foreach ($news as $news_item): ?> and this is detail view : Code: <div class="container"> this is my model : Code: public function get_news($slug = FALSE) display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]JoostV[/eluser] In your view, do: Code: <p><?php echo anchor('news/' . $news_item['slug'], 'View article') ?></p> display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]johanriyan[/eluser] nothing id. www.example.com/news/12345/example-news just appear : www.example.com/news/example-news how to handle in controller. display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]JoostV[/eluser] The reason I did not include the ID is because the ID is not used in your controller or model. For the code you posted you do not need to include the id. If you want to include the ID you will need to rewrite the rest of the code: Controller: Code: public function view($id, $slug) Model: Code: public function get_news($id = 0, $slug = FALSE) display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]johanriyan[/eluser] wauuwww... great. thks JoostV for fix it. display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]johanriyan[/eluser] thk u master JoostV display id and title in url Codeigniter - El Forum - 07-15-2013 [eluser]johanriyan[/eluser] master i want anything url like wordpress : www.example.com/2013/07/15/show-articel how to make it? hehe.... sorry master. display id and title in url Codeigniter - El Forum - 07-16-2013 [eluser]Pert[/eluser] Code: public function view($id = null, $slug = null) This is better (added default values). If you don't add default values to your controller method, following link would throw PHP error. <b>mydomain.com/view/</b> Because required method attributes are missing. |