Welcome Guest, Not a member yet? Register   Sign In
Library on Constructor Model
#1

[eluser]BanditXP[/eluser]
I'm upgrading my application from 1.7.3 to 2.0.1 and am having trouble using the library session in the constructor of a model.
In version 1.7.3 it worked.

Code:
<?php
class Test extends CI_Model
{
   $data = '';
   function __construct()
   {
      parent::__construct();
      $this->data = $this->session->userdata('id_user');
   }
}

Am I doing something wrong?
Thanks.
#2

[eluser]BanditXP[/eluser]
Forgot to mention what error occurs:
Code:
Fatal error: Call to a member function userdata() on a non-object in D:\xampplite\htdocs\site\application\models\test.php on line 19
#3

[eluser]InsiteFX[/eluser]
Code:
class Test extends CI_Model
{
   $CI;
   $data = '';

   function __construct()
   {
      parent::__construct();

      $CI = get_instance();
      $this->data = $this->CI->session->userdata('id_user');
   }
}

InsiteFX
#4

[eluser]toopay[/eluser]
Code:
class Test extends CI_Model
{
   protected $CI;
   protected $_data;

   function __construct()
   {
      parent::__construct();

      $this->CI =& get_instance();
      $this->_data = $this->CI->session->userdata('id_user');
   }
}
#5

[eluser]toopay[/eluser]
or simply...
Code:
class Test extends CI_Model
{
   protected $_data;

   function __construct()
   {
      parent::__construct();

      $CI =& get_instance();
      $this->_data = $CI->session->userdata('id_user');
   }
}
#6

[eluser]BanditXP[/eluser]
Ok, it worked.
Thanks guys.




Theme © iAndrew 2016 - Forum software by © MyBB