CodeIgniter Forums
Librairy vs model vs helper best place for authentification function ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Librairy vs model vs helper best place for authentification function ? (/showthread.php?tid=41060)



Librairy vs model vs helper best place for authentification function ? - El Forum - 04-26-2011

[eluser]Rushino[/eluser]
Hello,

For an authentification function that check login credentials, what would be the best place to put it ? What the main differences of each because this is a bit confusig.

Thanks!


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-26-2011

[eluser]Eric Barnes[/eluser]
I typically use a library and a few helpers to handle my auth. The library logs them in, verifies, etc. Then a helper is just for things like: is_logged_in() so I can have conditionals in the views.


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-26-2011

[eluser]Rushino[/eluser]
So there no problems in using models in a library ? Or should i use db function without the model directly in th lib ? (just looking for best practice)


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-26-2011

[eluser]Eric Barnes[/eluser]
My take on it is the db stuff can either be in the library or moved to a model. The beauty of CodeIgniter is that you can do things that may not be "recommended" but it still works just fine.

Take a look at this three part tutorial which should help you out and get you up to speed:
http://www.gregaker.net/2010/dec/06/creating_a_simple_auth_class_for_codeigniter_part_one/


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-26-2011

[eluser]InsiteFX[/eluser]
You can load models in library, but for libraries you will need to the CI Super Object!
Code:
class library {

    private $CI;

    public function __construct()
    {
        $this->CI =& get_instance();

        $this->CI->load->model('model_name');
    }
}

// You will then have to use:
$this->CI  // to access models db etc!

InsiteFX


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-27-2011

[eluser]toopay[/eluser]
typo!
Code:
// too much 'n'
$this->CI =& get_innstance();

and NO CODE! ;-P


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-27-2011

[eluser]InsiteFX[/eluser]
Fixed thanks, my keyboard sticks on some keys some time repeating them. Guess it's time to replace it LOL

InsiteFX


Librairy vs model vs helper best place for authentification function ? - El Forum - 04-27-2011

[eluser]Rushino[/eluser]
I think i will do as you suggested InsiteFX. The reason is that i do not want to repeater DB functions in my lib if they are available in the model that wouldnt be smart. So i will use that CI super object afterall lol