Reputation: 65
I am developing a website using the MVC pattern with the CodeIgniter framework.
I have 2 controllers:
class Site extends CI_Controller {
public function index() {
$this->view ();
}
public function view($page = 'home') {
if (! file_exists ( "application/views/pages/$page.php" )) {
show_404 ();
}
$data ['page'] = 'pages/' . $page;
$this->load->view ( 'template/template.php', $data );
}
}
class Members extends CI_Controller {
public function __construct() {
$this->load->model ( "members_model" );
}
public function login() {
$this->members_model->login ();
}
}
$route ['default_controller'] = "site";
$route ['(:any)'] = "site/view/$1";
So now I have a little problem which is when I call the members controller, it'll look for a page named members and not a controller named members.
What can I do to fix that?
Upvotes: 0
Views: 34
Reputation: 4430
you have to create other route for Members
$route ['members'] = "members";
$route ['members/(:any)'] = "members/$1";
$route ['default_controller'] = "site";
$route ['(:any)'] = "site/view/$1";
note that order is matter, the route above will use members
first when matched route detected.
Upvotes: 1
Reputation: 7068
You should add a specific route rule for that controller, like this one:
$route['members/(:any)'] = 'members/$1';
Or maybe add one for each method in your controller, like:
$route['members/login'] = 'members/login';
Note that you would need to add this/these rules to your routes.php
file, but before any other rule that can match it. So you should got from the most specific to the most general rule.
Upvotes: 0