codeigniter, admin system and auto load
Hello im working on a project and i have a footer and a sidebar that i want to load some information from the database, how ca开发者_JS百科n i do so it load the same on all pages.
i want to make a admin system to, how should i do that?, do i need to have a new codeigniter instillation or can i just create a new map in my controller,model and view maps ?.
how you guys doing it?.
The way I would go about it is create a MY_Controller and then put all of your generic logic inside of it and then all of your other controllers extend your MY_Controller. This saves you having to fetch content repeatedly and define and write the same code over and over again inside of your controllers. See Phil Sturgeon's article on base classes and keeping it DRY.
For templating your site including an admin panel, Phil Sturgeon has also created a simple template library that allows you to have themes on your site with different layouts you can switch between, etc.
As for creating an admin panel, Phil has also written a post on the subject as well and he goes into quite a bit of detail about the various ways you can develop an admin panel, which approach is best, etc. Some of the comments on the article are also very helpful too. Read his admin article here.
The templating method I usually use is as such... (it obviously is dependent on whether your sidebar, in your design, comes before/after the "content" in your markup)
<? $this->load->view('path/to/header') ?>
//content of page
<? $this->load->view('path/to/sidebar') ?>
<? $this->load->view('path/to/footer') ?>
Now if you are going to have variables you will need for every view, you can load them globally like so in the constructor of your controller.
$data->some_variable = $some_information;
$this->load->vars($data);
This will make $some_variable
available to all views you load from that controller.
An admin system is simply another area of your site/application that is simply protected by an authentication system. You first need a way to verify the user's identity. I generally use Ion_Auth as my preferred auth library, and I have done a fairly extensive write-up on how to set up Ion_auth and your "protected" Controllers in a very clean fashion.
精彩评论