CodeIgniter Forums
General question about framework extensions (also Ion Auth) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: General question about framework extensions (also Ion Auth) (/thread-31315.html)



General question about framework extensions (also Ion Auth) - El Forum - 06-14-2010

[eluser]Eric_WVGG[/eluser]
Hello, I'm an experienced PHP dev but new to formal frameworks. I'm adding Ion Auth to a project and have a question about "best practices."

What I'm specifically wondering is, what's the best way to call the Auth controller? Should I be extending the Auth class [first example below], calling the Auth class from within my own controller [second example], or just edit the Auth controller to call my own views and whatnot? [this seems crazy so I won't bother outlining it]

... examples

<code>Class My_Auth extends Auth {
function __construct() {
parent::__construct();
}
function index() {
$this->load->view( 'my_header' );
parent::index();
$this->load->view( 'my_footer' );
}
...</code>

vs

<code>
Class My_Auth extends Controller {
function index() {
$auth = new Auth;
// do stuff
}
...</code>

Thank you in advance for any thoughts.


General question about framework extensions (also Ion Auth) - El Forum - 06-14-2010

[eluser]Jelmer[/eluser]
I think you need to read up a bit more on what exactly a controller is. Auth normally needs to be checked from everywhere, not just from within a single Auth controller. You can only use 1 controller at a time, so if you implement Auth using a controller you can't use those functions anywhere else.

The best way is almost always to implement it as a library (likely using a few models for users and roles). And then to either put it in the autoload.php config file or use it something like this for a controller that always needs a login (like an Admin):

Code:
Class Admin extends Controller {
    function __construct() {
        parent::__construct();
        $this->load->library('Auth');
        $this->auth->check_login();
    }

    ...
}

But mostly read up a bit more on the MVC pattern as implemented by CI because I'm getting the feeling you're not fully grasping the basics.


General question about framework extensions (also Ion Auth) - El Forum - 06-20-2010

[eluser]Ben Edmunds[/eluser]
Cowboy_X,

I second Jeimer's suggestions, read up on MVC a little more and try to understand the gist of how CodeIgniter handles controllers and libraries.

If it's any help check out my example CodeIgniter project on Github here: http://github.com/benedmunds/CodeIgniter-Standard-Project

It's just a basic site skeleton but it should show how to setup the basics and also it uses Ion Auth so you can see how that is structured as well.