Welcome Guest, Not a member yet? Register   Sign In
Access to libray or model from another model
#1

[eluser]Unknown[/eluser]
Hello people. I am sorry for my bad english. But I have a question. Can I load the library or model from another model?

This error
"A PHP Error was encountered
Severity: Notice
Message: Undefined property: Files_model::$catalog
Filename: models/files_model.php
Line Number: 9
Fatal error: Call to a member function set_cat_type() on a non-object in D:\server\www\lehe\core\application\models\files_model.php on line 9"
appears when I tryed to execute this code:

Code:
class Files_model extends Model
{
    function __construct()
    {
        parent::Model();
        $this->load->library('catalog');
        $this->catalog->set_cat_type('files');
    }

        function get_file_list()    
        {
                return $this->catalog->get_catalog_list();
        }

          . . . . . .
}
#2

[eluser]m4rw3r[/eluser]
Models have problems with accessing libraries and such, use the CI instance instead:
Code:
$CI =& get_instance();
$CI->load->library('catalog');
$CI->catalog->set_cat_type('files');
#3

[eluser]Unknown[/eluser]
Thank you. It is working! =)




Theme © iAndrew 2016 - Forum software by © MyBB