You really should be using a MY_Controller because you can separate
your backend form your frontend etc;
Save as: ./application/core/MY_Controller.php
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* -----------------------------------------------------------------------
* Editor : PhpStorm
* Date : 1/12/2018
* Time : 7:40 AM
* Authors : Raymond L King Sr.
* -----------------------------------------------------------------------
*
* Class MY_Controller
*
* @project ci3admin
* @author Raymond L King Sr.
* @link http://www.procoversfx.com
* @copyright Copyright (c) 2009 - 2018 Custom Software Designers, LLC.
* @license http://www.procoversfx.com/license
* -----------------------------------------------------------------------
*/
/**
* Class BaseController
*/
class BaseController extends CI_Controller
{
/**
* Class properties - public, private, protected and static.
* -----------------------------------------------------------------------
*/
/**
* Data variable for views.
*
* @var array
*/
public $data = [];
/**
* __construct ()
* -----------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*/
public function __construct()
{
parent::__construct();
log_message('debug', "Base Controller Class Initialized");
}
/**
* render ()
* -------------------------------------------------------------------
*
* @param string $page
* @param array|null $params
*/
public function render(string $page, array $params = NULL)
{
if ($params !== NULL)
{
$this->data['data'] = $params;
}
$this->data['page'] = $page;
$this->load->view($page, $this->data);
}
// -----------------------------------------------------------------------
} // End of Base Controller Class.
/**
* Class Backend
*/
class Backend extends BaseController
{
/**
* Class properties - public, private, protected and static.
* -----------------------------------------------------------------------
*/
/**
* __construct ()
* -----------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*/
public function __construct()
{
parent::__construct();
log_message('debug', "Backend Controller Class Initialized");
}
// -----------------------------------------------------------------------
} // End of Backend Controller Class.
/**
* Class Frontend
*/
class Frontend extends BaseController
{
/**
* Class properties - public, private, protected and static.
* -------------------------------------------------------------------
*/
/**
* __construct ()
* -------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*/
public function __construct()
{
parent::__construct();
log_message('debug', "Frontend Controller Class Initialized");
}
// -------------------------------------------------------------------
} // End of Frontend Controller Class.
// End of MY_Controller Controller Class.
/**
* -----------------------------------------------------------------------
* Filename: MY_Controller.php
* Location: ./application/controllers/MY_Controller.php
* -----------------------------------------------------------------------
*/
Then extend all of your other controllers with either ( Backend or Frontend )
Like so:
Save as: ./application/controllers/admin/Users.php
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* -----------------------------------------------------------------------
* Editor : PhpStorm
* Date : 2/3/2018
* Time : 7:34 AM
* Authors : Raymond L King Sr.
* -----------------------------------------------------------------------
*
* Class Users
*
* @project ci3admin
* @author Raymond L King Sr.
* @link http://www.procoversfx.com
* @copyright Copyright (c) 2009 - 2018 Custom Software Designers, LLC.
* @license http://www.procoversfx.com/license
* -----------------------------------------------------------------------
*/
class Users extends Backend
{
/**
* Class properties - public, private, protected and static.
* -----------------------------------------------------------------------
*/
/**
* __construct ()
* -----------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*/
public function __construct()
{
parent::__construct();
// restrict this controller to admins only
$this->auth->restrict('admin');
log_message('debug', "Users Controller Class Initialized");
}
/**
* index ()
* -----------------------------------------------------------------------
*
*/
public function index()
{
}
/**
* add ()
* -------------------------------------------------------------------
*
*
*/
public function add()
{
}
/**
* edit ()
* -------------------------------------------------------------------
*
*
*/
public function edit()
{
}
/**
* retrieve ()
* -------------------------------------------------------------------
*
*
*/
public function retrieve()
{
}
/**
* delete ()
* -------------------------------------------------------------------
*
* @param int $id
*/
public function delete(int $id)
{
$this->db->where('id', $id)
->delete('users');
$this->render('users/delete_success');
}
/**
* manage ()
* -------------------------------------------------------------------
*
* Manage users in the users database table.
*
*/
public function manage()
{
$this->load->library('table');
$data = $this->db->get('users');
$result = $data->result_array();
// Setting headings for the table
$this->table->set_heading('Username', 'Email', 'Actions');
foreach ($result as $value => $key)
{
// Build actions links
$actions = anchor("admin/users/edit/".$key['id']."/", "Edit").
anchor("admin/users/delete/".$key['id']."/", "Delete");
// Adding row to table
$this->table->add_row($key['username'], $key['email'], $actions);
}
// Load the view
$this->render('users/manage');
}
// -----------------------------------------------------------------------
} // End of Users Controller Class.
/**
* -----------------------------------------------------------------------
* Filename: Users.php
* Location: ./application/controllers/admin/Users.php
* -----------------------------------------------------------------------
*/
That should give you a start.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )