I need to make custom URL in Codeiginter to display links from
domain.com/news/id/1 to domain.com/article-name.html
i want it dynamic to all news id not just one link
can i do it in codeiginter or not ?
I need to make custom URL in Codeiginter to display links from
domain.com/news/id/1 to domain.com/article-name.html
i want it dynamic to all news id not just one link
can i do it in codeiginter or not ?
Yes you can, This is called URL rewrite. I can explain here but the official documentation is far better.
here it is: http://ellislab.com/codeigniter/user-guide/general/urls.html
In your config.php
file do this:
$config['url_suffix'] = '.html'; // this line might actually not be necessary, i forget
In routes.php
set this:
$route['article-name.html'] = "news/id/1";
Let me know if you get any errors.
Step 1: Set your default controller in routes.php
$route['default_controller'] = 'get_article';
Step 2: Set your config.php to put .html on the end
$config['url_suffix'] = '.html';
Step 3: Create the Controller
// path: /codeigniter/2.1.4/yourAppName/controllers/get_article.php
<?php
class Get_article extends CI_Controller {
public function index($article = '')
{
// $article will be "article-name.html" or "article2-name.html"
if($article != '')
{
$pieces = explode('.', $article);
// $pieces[0] will be "article-name"
// $pieces[1] will be "html"
// Database call to find article name
// you do this
$this->load->view('yourArticleView', $dbDataArray);
}
else
{
// show a default article or something
}
}
}
?>