display id and title in url Codeigniter |
[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.
[eluser]JoostV[/eluser]
Code: $id = 12345;
[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)
[eluser]JoostV[/eluser]
In your view, do: Code: <p><?php echo anchor('news/' . $news_item['slug'], 'View article') ?></p>
[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.
[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)
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |