Im new to CodeIgniter and I would like to change my URL from
to
in CI with route. How can i achieve this with URL Route ?
My Table Posts
posts_id
posts_name
My Home View (to call the posts)
Im using url title for the url:
<a href="<?php echo base_url("{$v['posts_id']}/".url_title($v['posts_name'], "-", true)) ?>">
My Posts Controller
<?php
defined('BASEPATH') OR exit ('No direct script access allowed');
class Posts extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Posts_model');
}
public function index()
{
show_404();
}
public function details($posts_id=NULL,$posts_name='') {
$data['title'] = $this->Posts_model->select_content_by_id($posts_id);
$data['data'] = $this->Posts_model->select_content_by_id($posts_id);
$this->load->view('posts',$data);
}
}
My Posts Model
<?php
defined('BASEPATH') OR exit ('No direct script access allowed');
class Posts_model extends CI_Model{
public function dsPosts()
{
return $this->db->get('posts')->result_array();
}
public function select_content_by_id($posts_id)
{
return $this->db->where('posts_id',$posts_id)->get('posts')->result_array();
}
}
My Route
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['(:num)'] = 'posts/details/$1';
$route['(:num)/(:any)'] = 'posts/details/$1/$2';