Welcome Guest, Not a member yet? Register   Sign In
How to get $CI to access my called class (SOLVED)
#1

[eluser]prestondocks[/eluser]
Hi, I am trying to impliment a security system in my application and I want to use hooks.

My plan is to use post_controller_constructor. I then want my hook method to get a data member variable in the called class. This will hold an array of methods that a guest user is able to access. The hook will then be redirected to an error page if the user is not logged in and the called method does not exist in this array.

My question is how do I get my hook method to get the data member from my called class.

Below is an example of what I am trying to do

controller code

Code:
class Meetings extends Controller
{
  var $security_allow = array('book_meeting','delete_meeting','edit_meeting');
  .....
}

Example below of my hook method that does not work
Code:
class Module_security
{

function module_permission()
{
$CI =& get_instance();
$called_class = $CI->router->class;
$called_method = $CI->router->method;
$mod_sec = $CI->$called_class->security_allow;
......
}
}
#2

[eluser]n0xie[/eluser]
It's not the same but this is how I usually do it:
Code:
Class Some_Controller extends Security_Controller {

    protected $require_permission = array('details','edit','delete');

    function details() {}
    function edit() {}
    function delete() {}
}

class Security_Controller extends Controller {

    function __construct()
    {
        parent::__construct();
        $this->check_permission();
    }
    
    protected function check_permission()
    {
        if ( in_array($this->router->method, $this->require_permission) )
        {
            // do your checking here;
        }
    }
}
#3

[eluser]prestondocks[/eluser]
Thank you for the suggestion, I will use this solution




Theme © iAndrew 2016 - Forum software by © MyBB