Professional CodeIgniter

(singke) #1

Chapter 7: Improving the Dashboard


212


Here ’ s the MSizes model (/system/application/models/msizes.php):

< ?php
class MSizes extends Model{

function MSizes(){
parent::Model();
}
}//end class
? >

Finally, here ’ s the updated $autoload[‘model’] line from /system/application/config/autoload.php:

$autoload[‘model’] = array(‘MCats’, ‘MProducts’, ‘MOrders’, ‘MAdmins’,
‘MSizes’, ‘MColors’);

Creating Admin Screens for Colors


You ’ re going to create a new Colors controller in the /system/application/controllers/admin folder. In
almost every respect, it ’ s going to be as simple as the admin/admins controller, so you might as well use
the admin/admins controller as your guide.

First is the initial setup and check for security credentials:

< ?php

class Colors extends Controller {
function Colors(){
parent::Controller();
session_start();

if ($_SESSION[‘userid’] < 1){
redirect(‘welcome/verify’,’refresh’);
}
}

The index() function is extremely simple. All you want to do is show all the colors that are available
in the colors database table.

function index(){
$data[‘title’] = “Manage Colors”;
$data[‘main’] = ‘admin_colors_home’;
$data[‘colors’] = $this- > MColors- > getAllColors();
$this- > load- > vars($data);
$this- > load- > view(‘dashboard’);
}

The create() function checks for POST data. If it finds POST data, it runs createColor(). Otherwise,
it displays the admin_colors_create view. (To save time, you ’ ll create all the model functions after you ’ re
done with the controller.)
Free download pdf