• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem: Can't call a model function in my library!

#1
[eluser]Jason van der Zeeuw[/eluser]
Hey all,

Here is my problem code:

Code:
var $CI; //Contains an instance of the library

    public function __construct() {
        $this->CI = & get_instance();
        $this->CI->load->model('mymodel');        
    }

    function test()
    {        
        return $this->mymodel->testmethod());
    }

I get 2 errors:

Message: Undefined property: My_library::$mymodel (so he doesn't knows 'mymodel')
&
Fatal error: Call to a member function testmethod() on a non-object

#2
[eluser]vrencianz[/eluser]
Try

Code:
$this->CI->mymodel->testmethod();

instead

#3
[eluser]InsiteFX[/eluser]
Code:
private $CI; //Contains an instance of the library

    public function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->model('mymodel');        
    }

    function test()
    {        
        return $this->CI->mymodel->testmethod());
    }

#4
[eluser]Jason van der Zeeuw[/eluser]
OMG thank you so much,
I feel so stupid Tongue

this is the first time I work with CI so thank you guys!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.