Professional CodeIgniter

(singke) #1

Chapter 6: Creating a Dashboard


153


If you were to attempt to log in, you ’ d only see a blank page. That ’ s because you still haven ’ t built out
the dashboard controller in the admin folder. That ’ s in the next section. But before doing that, take a
moment and add a “ dashboard ” link to the footer view, making it possible for admins to log in from
anywhere on the site:

Copyright < ?php echo date(“Y”);? >
< ?php echo anchor(“welcome/privacy”,”privacy policy”);? >
& nbsp; & nbsp; & nbsp;
< ?php echo anchor(“welcome/verify”,”dashboard”);? >

Creating the Home Page of the Admin Panel


Now it ’ s time to create a home page in the administrative dashboard. The process for creating this home
page will be extremely similar to the process you underwent to create the pages on the public side.

The first step is to create an index() function in the admin/dashboard controller. Once you ’ ve got that
in place, you will need some kind of admin template view that you can use to call all of your
administrative subviews that are included within it.

Instead of reusing the templates that are used on the public side, it ’ s probably a good idea to create a
generic - looking administrative UI that has fewer moving parts — but you can decide all of that in
a minute. The first step is to create the index() function.

function index(){
$data[‘title’] = “Dashboard Home”;
$data[‘main’] = ‘admin_home’;
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}

As you can see, the index() function here is nothing much to look at. It has a title, it loads a view called
dashboard , and it looks like you ’ re going to use a subview called admin_home at some point. There are no
model functions called here, because nothing on the dashboard page is dynamic at this point. That may
change, of course, but then all you have to do is call the model functions you need.

One more thing needs to be done before you can move on. Remember that you ’ re setting a PHP session
variable called userid if they successfully log in. You need to set a quick check for that variable at the
top of the controller, like this:

function Dashboard(){
parent::Controller();
session_start();
if ($_SESSION[‘userid’] < 1){
redirect(‘welcome/verify’,’refresh’);
}
}

What about the views? The first is the dashboard view. This view will be very similar to the main
template view you ’ ve been using on the public side, except that you won ’ t use quite as much of the look
and feel. In fact, you ’ ll be using a different CSS file.
Free download pdf