Welcome Guest, Not a member yet? Register   Sign In
Librairy vs model vs helper best place for authentification function ?
#1

[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!
#2

[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.
#3

[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)
#4

[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/crea..._part_one/
#5

[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
#6

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

and NO CODE! ;-P
#7

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

InsiteFX
#8

[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




Theme © iAndrew 2016 - Forum software by © MyBB