I am simply looking for methods of blocking my users who don't have rights from viewing particular pages. I tried putting together a function inside of my backend controller inside the codeigniter core folder and have all my backend controllers extend it. I wanted to put the function inside of their to keep with the DRY principal of putting this function inside of every controller.
I'm looking for maybe a different way of writting the function or just different ideas of what I should do with the function.
public function view_allowed($user_data)
{
if ($user_data->role_id != 4)
{
return false;
}
return true;
}
With this I would just call the function inside the contruct of the other controllers and do and if statement that if it returns false then direct to some other page that will say they don't have the right creditials to view that page.
Any questions, comments, concerns?
EDIT 2 :
I had to make an edit because I'm am pondering what this will do. Purpose of this what I want to do is run the function on each controllers construct that a regular user should not be able to view and only an admin can. So if I do the following how will it know to redirect to a different page if the user is not able to view that page.
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Recent_activities extends Backend_Controller
{
/**
* Load the parent construct and any additional models, helper, libraries available.
* @return void
*/
public function __construct()
{
parent::__construct();
$view_allowed = view_allowed($user_data);
}
public function index()
{
$this->breadcrumb->add_crumb('<li><a href="' . site_url() .
'control-panel/activities/recent-activities">Activities</a></li>');
$this->breadcrumb->add_crumb('Recent Activites');
$activities = $this->user->get_all();
$this->template
->title('Recent Activites')
->build('recent_activities_view');
}
}