我希望在我的应用程序中添加一些修改,以便在我的 MY_Controller 上检查是否允许用户访问当前页面。这是我的一个控制器的一个例子。我所有的都有读取、编辑、创建、删除功能。我只需要弄清楚如何全局设置权限以允许或禁止用户访问该函数,而不是在每个函数上执行 if 语句。
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Content_pages extends MY_Controller
{
/**
* Account::__construct()
*
* Load the parent construct and any additional models, helper, libraries available.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->load->model('content_page_model', 'content_page');
}
/**
* Content_pages::read()
*
* @return
*/
public function read()
{
//vardump($this->user_data);
// Checks to see if the user has a role id of four and if they do then it shows the admin dashboard and if not then shows the user dashboard.
if ($this->user_data->access_level_id >= 4)
{
// Retrieve all the users from the database that handle characters and assign it to the users variable.
$content_pages = $this->content_page->get_all();
// Place to dump the users array to verify it is the expected value.
// vardump($users);
// Checks to verify that there is data inside of the users array and that it is not empty.
if (!empty($content_pages))
{
$this->template->set('content_pages', $content_pages);
}
// Add the breadcrumbs to the view.
$this->breadcrumb->add_crumb('<li><a href="' . base_url() . 'wrestling-manager/control-panel" class="glyphicons home"><i></i> Control Panel</a></li>');
$this->breadcrumb->add_crumb('<li><i></i> Content Pages</li>');
$this->breadcrumb->change_link('<li class="divider"></li>');
// Sets all the properites for the template view.
$this->template
->set_theme('smashing')
->set_layout('control_panel_view')
->set_partial('header', 'partials/header')
->set_partial('sidebar','partials/sidebar')
->set_partial('footer', 'partials/footer')
->title('Content Pages')
->set('user_data', $this->user_data)
->build('content_pages_view');
}
else
{
echo 'haha';
//redirect('wrestling-manager/control-panel');
}
}
/**
* Content_pages::edit()
*
* @return void
*/
public function create()
{
echo 'testing for create function';
}
/**
* Content_pages::edit()
*
* @return void
*/
public function edit($content_page_id)
{
vardump($content_page_id);
}
public function delete($content_page_id)
{
vardump($content_page_id);
}
/**
* Content_pages::save()
*
* @return
*/
public function save()
{
echo 'testing for save function';
}
/**
* Content_pages::update()
*
* @return
*/
public function update()
{
echo 'testing for update function';
}
}