Controller's usage.. |
[eluser]fatnjazzy[/eluser]
Hi, I'm building a backend system. localhost/admin the localhost/admin will call to Admin controller and will build the views. building the view must use the database to build the user menus sessions and other stuff... now, inside the system i want to have another controller for lets say Articles management . localhost/admin/articles. the articles needs to be an independent controller and load the views for the articles and the basic template like the admin. how do i suppose to do it? hope you understood me. Thanks
[eluser]Jamie Rumbelow[/eluser]
You can create a subdirectory in the application/controllers folder called admin, and any controllers created within that will have the admin/ prefix. You can override this with custom routing, just like normal if you need to. Jamie
[eluser]Jeremy Gimbel - Conflux Group[/eluser]
You may not need an admin controller, so to speak, and really just a subfolder like Jamie mentioned. You might use a route to point /admin/ to an /admin/dashboard controller or somehting like that, and go from there with controllers in the /admin folder for each of the additional areas of the admin pane you're creating. Jeremy
[eluser]fatnjazzy[/eluser]
OK, to 2 questions regarding that. 1. how to change the router to support that? localhost/admin/articles_controller localhost/admin/dashboard_controller 2. in order to render the admin template i need to perform some queries from the database. how do i avoid duplicate that code foreach controller? thanks for the reply.
[eluser]Jeremy Gimbel - Conflux Group[/eluser]
If the URL matches the actual subfolder/controller combination you're using, then no routes are needed. You only need routes if you want to map a specific URL to another controller. For instance if you have a controller in /admin/ called Dashboard, and you want http://hostname/admin to point to it, you'd use the route: Code: $route['admin'] = 'admin/dashboard'; To run the database queries, you'd want to be using a model. Generally, your models follow the tables of your database, but with a split admin and front end system, you might want a separate set of models for each. If you want models shared between both of the modules, then you should be able to put them in the main models folder, instead of inside the module models folder. |
Welcome Guest, Not a member yet? Register Sign In |