i've recently started using codeigniter and i'm having a few issues with my routing. I feel like i may have missed something in the way that it's meant to work, despite reading the documentation.
I've currently managed to route the default controller to execute the correct method in a class i've got, but when i try the same process for say, a second function with an argument, i get a Page not found error. Is my routing the issue here, or is there a problem with one of the methods?
Routing:
$route['(:any)'] = 'front/index/$1';
$route['/category/(:any)'] = 'front/category/$1';
$route['default_controller'] = 'front';
Database Model (News_model.php)
class News_model extends CI_Model {
public function __construct() {
$this->load->database();
}
public function get_news_latest() {
$query = $this->db->get('chanl_posts', 20);
return $query->result_array();
}
public function get_news_category($category) {
$query = $this->db->get_where('chanl_posts', array('category' => $category));
return $query->row_array();
}
}
Controller (Front.php)
class Front extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
$this->load->helper('url_helper');
}
public function category($category)
{
$data['news_item'] = $this->news_model->get_news_category($category);
if (empty($data['news_item']))
{
show_404();
}
$this->load->view('templates/header', $data);
$this->load->view('front/index', $data);
$this->load->view('templates/footer');
}
public function index() {
$data['news'] = $this->news_model->get_news_latest();
$this->load->view('templates/header', $data);
$this->load->view('front/index', $data);
$this->load->view('templates/footer');
}
}