Welcome Guest, Not a member yet? Register   Sign In
Access to libraries in MY_Model
#1

Hi! I face with problem discussed in this old post and solution never was found.
http://forum.codeigniter.com/archive/ind...844-1.html

Funny that in MY_Controller everything is fine. Any suggestions? Maybe someone faced with it too?
Reply
#2

Get the CI super object.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-27-2015, 04:20 PM)InsiteFX Wrote: Get the CI super object.

In CI_Model we have magic method


Code:
/**
     * __get
     *
     * Allows models to access CI's loaded classes using the same
     * syntax as controllers.
     *
     * @param    string
     * @access private
     */
    function __get($key)
    {
        $CI =& get_instance();
        return $CI->$key;
    }

So in MY_Model in usual case u dont need get super object cause if u dont have property or method - it will be looking at super object.

That is the first note. Second - even if I get super object clearly $CI =& get_instance(); and load library $CI->load->library('my_lib');

when i try to run some method $CI->my_lib->some_method it throws error like i mention before

Call to a member function some_method on a non-object in... MY_Model and so on...
Reply
#4

Try just loading the library in your controller then call your library methods in your model.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 09-29-2015, 04:57 AM by scion.)

(09-28-2015, 11:01 AM)InsiteFX Wrote: Try just loading the library in your controller then call your library methods in your model.

Thats why I write here - I try to load library in MY_COntroller (or Public_Controller or whatever Controller) and in MY_Model i get error describe above.

I dont understand why this is working so, but i found the solution. In base MY_Controller I get super object like next:


PHP Code:
$ci =& get_instance();
 
      
$ci
->login false;
 
      
$ci
->_user null;
 
      
 
if($this->ion_auth->logged_in() && !$this->ion_auth->is_admin())
 {
 
          $ci->login true;
 
          $ci->_user $this->ion_auth->user()->row();
 
 

After that I can assecc to login and user in any Controller or MY_Model or Model with simple $this->login and $this->_user

Thanks for participation in the discussion

 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB