Welcome Guest, Not a member yet? Register   Sign In
loading model from controller subfolder
#1

[eluser]PermanaJ[/eluser]
I've got one problem .. I have a create a folder in controller folder, then I add a controller file. From there, I load a model in models folder ... and there are some error

I have search in forum about controller/model with subfolder but it didn't solve my problem ..

ohh, here's the code

application/library/MY_Model.php
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Model extends Model{

public function __construct( ) {
    parent::Model();
    $this->load->database();
}

public function read($column_name, $where = array() ){
    
    $this->db->select($column_name);

    if(isset($where)){
        $this->db->where($where);
    }
    
    $value = $this->db->get($this->table);
    return $value->result_array();
}

}

application/models/muser.php
Code:
class MUser extends MY_Model{

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

application/controller/user/account.php
Code:
/**
* @property MUser $MUser
*/
class Account extends MY_Controller {

    public function __contruct() {
        parent::__construct();
        $this->load->model('MUser');
        $this->load->language('user',$this->get_language() );
        
        if($this->session->userdata('user_id') == false){
            show_error(lang('user_login_first'));
        }
    }

    public function index() {

        $where = array('user_id' => $this->session->userdata('user_id'));

        //here's the error. line below is line 31
        $acc_data = $this->MUser->read('username, email, nickname', $where);

    }
}

And here's the error message :

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Account::$MUser

Filename: user/account.php

Line Number: 31


Fatal error: Call to a member function read() on a non-object in D:\CodeIgniter\Test\system\application\controllers\user\account.php on line 31

Why this error happen? I think there are any problem with creating folder inside controller folder ...
#2

[eluser]bd3521[/eluser]
Try using Muser instead of MUser?




Theme © iAndrew 2016 - Forum software by © MyBB