General question about framework extensions (also Ion Auth) |
[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.
[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 { 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.
[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...rd-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. |
Welcome Guest, Not a member yet? Register Sign In |