Welcome Guest, Not a member yet? Register   Sign In
Extending Ion_auth

I want to add some extra functions to Ion_auth, e.g. to get a list of e-mail addresses or names from the users table. I don't want to overwrite the standard library or model that comes with Ion_auth. How can I safely extend the model or the library? Where do I put my own files?

Same way you extend any library.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

I know how to extend the native classes. E.g. MY_model extends CI_model.
But the Ion_auth library loads the Ion_auth_model. So I guess it's a bit more complicated to extend either the library or the model or both. I could use a few helpful tips.

(This post was last modified: 04-02-2016, 03:26 PM by Tpojka.)

Make new library e.g. Get_mail_lib.php with next code

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('Not your cup of tea.');


Get_mail_lib extends Ion_auth
    private $_CI;

    public function __construct()
        $this->_CI = &get_instance();//for using rest of CI objects/functions
// extend your own methods here

Than, in controller call your newly created library as always you would:

PHP Code:

I solved it by renaming the original model to "Ion_auth_o_model.php". I created a new model Ion_auth_model that extends the original. Maybe not the most elegant way to do it, but it works.

There is few solutions.
You can work with extended model or extended library.
As mentioned by yourself Ion_auth library automatically loads Ion_auth_model.
I think that every method from example controller uses library methods not from model.
So extending the library you would have access to model too.
Considering speed, if you don't need library itself loaded and just need model methods, you made it that way already.

I didn't change the library. I only extended the model. All function calls are like $this->ion_auth->...., so I'm only using library methods, not directly into the model.
By extending the model, I can implement my own functions and call them like any other ion_auth method.

Theme © iAndrew 2016 - Forum software by © MyBB