简体   繁体   English

从codeigniter中的文件夹加载模型

[英]load model from folder in codeigniter

I am using codeigniter and handing admin side and users side separately. 我正在使用codeigniter并分别处理管理员端和用户端。 now i have model which is in admin folder and i want to call in controller of users. 现在我的模型在管理员文件夹中,我想在用户的控制器中调用。 but when i am trying to load model from admin folder 但是当我试图从管理文件夹加载模型时

$this->load->model('admin/myinterest_model');

$data['myInterest'] = $this->myinterest_model->selectResult('user',  $this->session->userdata['Id']);

it shows following error 它显示以下错误

Message: Undefined property: Users::$myinterest_model
Filename: controllers/users.php

Please guide me how to load model from admin 请指导我如何从管理员加载模型

$this->load->model('admin/myinterest_model' , 'myinterest');

The second parameter (optional) is used to call the method. 第二个参数(可选)用于调用方法。

ex: 例如:

$this->myinterest->get_users();

try this call constructor in controller and load model into it 在控制器中尝试此调用构造函数并将模型加载到其中

function __construct()
    {
        // Initialization of class
        parent::__construct();

        // load the model
        $this->load->model('admin/myinterest_model');
    }

create a folder inside your models folder (application/models/admin) and put your admin files in there ( M yinterest_model.php) 模型文件夹(application / models / admin)中创建一个文件夹并将管理文件放在那里M yinterest_model.php)
now in your controller just call your model 现在在您的控制器中只需调用您的模型

$this->load->model('admin/myinterest_model');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM