Create An Admin Area In CodeIgniter 3
Hello friends. In this tutorial, we will learn how to create an admin area in codeigniter 3. Every respectable blog must have an admin area. In CodeIgniter there are a lot of methods to create such an area. In this tutorial we will simply make a directory named admin inside the controllers directory and also an admin directory inside the views directory. So let’s start with code
Step 1 – Create an admin area in CodeIgniter 3
First of all we create the directories mentioned below.
[code]
-application/
– -controllers/
– – -admin/
– -views/
– – -admin/[/code]
Now create a controller named Dashboard (Dashboard.php) inside the application/controllers/admin directory:
[code]<?php defined(‘BASEPATH’) OR exit(‘No direct script access allowed’); class Dashboard extends Admin_Controller { function __construct() { parent::__construct(); } public function index() { $this->load->view(‘admin/dashboard_view’);
}
}[/code]
As you can see, the index() method of the dashboard class will load dashboard_view which is loaded from the views/admin directory. Create view file named dashboard_view.php which will look like this:
[code]
<?php defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Meul Tech Dashboard</title>
</head>
<body style="text-align:center;padding:100px;">
<div id="container">
<h1>Meul Tech Admin Dashboard!</h1>
<h3>Admin area in CodeIgniter 3.x</h3>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === ‘development’) ? ‘CodeIgniter Version <strong>’ . CI_VERSION . ‘</strong>’ : ” ?></p>
</div>
</body>
</html>
[/code]
After we’ve done all this, we must make sure that when someone goes to http://localhost/admin, he/she will be taken to the dashboard. To do this we simply add a route inside the routes.php file. Now, the file will look like this:
[code]<?php
defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
$route[‘default_controller’] = ‘welcome’;
$route[‘404_override’] = ”;
$route[‘translate_uri_dashes’] = TRUE;
$route[‘admin’] = ‘admin/dashboard’;[/code]
Important thing to note in Dashboard is extending Admin_Controller. In this tutorial I decided to creating more than one single MY_Controller. So, MY_Controller.php will look like this for now:
[code]<?php defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
class MY_Controller extends CI_Controller
{
function __construct()
{
parent::__construct();
}
}
class Admin_Controller extends MY_Controller
{
function __construct()
{
parent::__construct();
}
}
class Public_Controller extends MY_Controller
{
function __construct()
{
parent::__construct();
}
}[/code]
That’s it. We now have an admin area. Thanks for reading this tutorial.
Don’t forget to share your doubts in the comment box and also share this post on social media and with your friends because “You share, I share, let’s make the world aware”.
You may want to take a look at the following related posts:
- Ajax Login System in PHP Codeigniter
- Create A Rich Text Editor Using TinyMCE In Codeigniter
- Create, Read, Update and Delete Records in Codeigniter using Ajax – CRUD OPERATION
- Create A Simple Website Using Codeigniter
Also for more awesome tutorials, please don’t forget to like our facebook page Meul Tech .
Bonus: We also give training on following topics:
1. Angular Training in Mumbai.
2. Bootstrap Training Course in Mumbai.
3. Web Designing Training in Mumbai.
4. UI / UX Training.