Reputation: 109
I have a question concerning setting rules for routing in codeigniter. In the basic welcome tutorial included in the document with the framework, the default routing is
$route['default_controller'] = "welcome";
that is, the file with the class name 'welcome' is located in the controller folder, and the welcome_view.php is located in the view. But if I create a new folder in the controller folder and name it Welcome then move welcome.php to it? Then I do it the same in the view (create a folder named Welcome_view then move the welcome_view.php into it). What will the route for the default_controller be ? Thank you very much.
Upvotes: 0
Views: 250
Reputation: 7388
Indeed, you can add folders inside your controllers folder. This is covered in the CodeIgniter Documentation.
You would change the route to: $route['default_controller'] = "Welcome/welcome";
If you choose to follow the same convention for the views this is okay, but it is not a requirement. You could still leave your view where it is load it using:
$this->load->view('welcome');
Otherwise, if you do follow the same convention and sub-folder it out you would call:
$this->load->view('welcome/welcome');
Upvotes: 1
Reputation: 25435
In that case (welcome.php inside welcome folder), the route will be:
$route['default_controller'] = "welcome/welcome";
CI makes an attempt to map the route as folder[/subfolders]
if at first doesnt match the regular pattern controller/method, before throwing the show_404() error.
The above route will call the index() method on the Welcome class inside the welcome folder, assuming you have no welcome class directly in the controllers folder, of course.
Same applies for views: if you want to map to a view inside a subfolder, you call it with:
$this->load->view('welcome/welcome');
which fetches the welcome.php file inside the views/welcome/
folder.
Upvotes: 0