Welcome Guest, Not a member yet? Register   Sign In
Benefit of extending the controller for providing authorization rather than a hook?
#1

[eluser]gidarren[/eluser]
Hey guys, I just created an authorization hook which is like less than a 100 lines of codes that uses models and provides a role based ACL system. I was wondering why people create extensive libraries or extend the main controller to achieve this? Basically my method works by:
1. Defining allowed folders (modules), controllers, and methods.
2. Checking against those.
3. Checking if the user is logged in, if not redirecting them to appropriate login area if module/controller/method isn't allowed.
4. If not logged in redirects them to allowed login controller and method.
5. If logged in checks their permissions against a database which checks if they have permissions for that page.
6. If they don't have permission redirects them to a specific page (e.g. dashboard).

What I cannot understand is why people are making complex solutions that extend the main controller. I can see if it was modular based (e.g. but still you can use folder checking), but I cannot see why it is necessary for an overall application.

Even if the sub folder requires its own authorization class at that level, wouldn't it be wiser to make it a separate application?

Just thinking guys, just thinking.
#2

[eluser]n0xie[/eluser]
I think extending a base class is about a 100 times more simple than whatever you just described...
#3

[eluser]kirkaracha[/eluser]
Extending the main controller isn't really that complicated.
Code:
class Admin_Controller extends CI_Controller {

    protected $is_admin;

    function __construct(){  
        parent::__construct();

        $this->is_admin = $this->session->userdata('is_admin');
        if($this->is_admin == FALSE){
            redirect('/login');
        }
    }

} // Admin_Controller




Theme © iAndrew 2016 - Forum software by © MyBB