Welcome Guest, Not a member yet? Register   Sign In
Could not load model over Autoload
#1

Hey,

i have a little strange Problem. When i try to load a model over the Autoload.php and try to use it, i'll become an Error that the model could not found (Undefined property: Home::$users_to_groups), but when i load it over $this->load->model() it works. But why?

Here is the Code that i Use:
PHP Code:
<?php

class Rights_management {
 
   private $_ci null;
 
   private $_aGroupIds = [];

 
   public function __construct() {
 
       $this->_ci get_instance();

 
       //$this->_ci->load->model('rights/Users_to_groups_model', 'users_to_groups');
 
       $this->_aGroupIds $this->_getUserInformation();
 
   }

 
   private function _getUserInformation() {
 
       $aAccountData element('accountData'$this->_ci->session->userdata());

 
       if(!empty($aAccountData)) {
 
           $iUserId element('id'$aAccountData);

 
           return array_column($this->_ci->users_to_groups->getGroupIds($iUserId), 'group_id');
 
       }

 
       return [];
 
   }

 
   public function checkAccess($sCode) {
 
       return $this->_ci->groups_to_rights->checkAccess($sCode$this->_aGroupIds);
 
   }


Has anywhone an Idea what i do wrong? When i insert the commented Line, than the script is full functionally (the groups_to_rights modal can be found).
Reply
#2

Your class needs to extend CI_Model.
http://www.codeigniter.com/user_guide/ge...odels.html
Reply
#3

No. The Class that i linked is a Library to a Model.
Reply
#4

(This post was last modified: 02-15-2016, 12:21 PM by mwhitney.)

How are you listing the model in your config/autoload.php file? To get the same result as this:

PHP Code:
$this->_ci->load->model('rights/Users_to_groups_model''users_to_groups'); 

You need to use something like this:

PHP Code:
$autoload['model'] = ['rights/Users_to_groups_model' => 'users_to_groups']; 

However, it should also be noted that this depends on where you are attempting to use the model. Classes in the autoload config are not loaded until the Controller's constructor has been executed, so some hooks will execute before the model is loaded.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB