[英]multiple model not load in same controller in codeigniter
i want to run multiple model in same controller but its show below error我想在同一个控制器中运行多个模型,但它显示以下错误
Severity: Notice严重性:注意
Message: Undefined property: Home::$Company消息:未定义的属性:Home::$Company
Filename: controllers/Home.php文件名:控制器/Home.php
Line Number: 23行号:23
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct ();
$this->load->model('Product');
$this->load->model('Company');
//$this->load->model(array('Product','Company'));
}
public function index()
{
$Product = $this->Product->getProduct(10);
if($Product)
{
$data['Product'] = $Product;
}
$Company = $this->Company->getCompany(10);
if($Company)
{
$data['Company'] = $Company;
}
$this->load->view('Home',$data);
}
}
//Company Model //公司模式
class Company extends CI_Controller {
function getCompany($limit=null,$start=0)
{
$data = array();
$query = $this->db->query('SELECT * FROM user as u,category as c,sub_category as sc WHERE c.Category_Id=u._Category_Id and u._Sub_Category_Id=sc.Sub_Category_Id ORDER by rand() limit '.$start.','.$limit);
$res = $query->result();
return $res;
}
function getOneCompany($id)
{
$this->db->where('User_Id',$id);
$query = $this->db->get('user');
$res = $query->result();
return $res;
}
}
// Product model // 产品型号
class Product extends CI_Controller {
function getProduct($limit=null,$start=0)
{
$data = array();
$query = $this->db->query('SELECT * FROM product as p,user as u,category as c,sub_category as sc WHERE p._User_Id = u.User_Id and c.Category_Id=u._Category_Id and u._Sub_Category_Id=sc.Sub_Category_Id ORDER by rand() limit '.$start.','.$limit);
$res = $query->result();
return $res;
}
function getOneProduct($id)
{
$this->db->where('User_Id',$id);
$query = $this->db->get('user');
$res = $query->result();
return $res;
}
}
$models = array(
'menu_model' => 'mmodel',
'user_model' => 'umodel',
'admin_model' => 'amodel',
);
foreach ($models as $file => $object_name)
{
$this->load->model($file, $object_name);
}
Your models start with你的模型开始于
class Company extends CI_Controller {
They should be他们应该是
class Company extends CI_Model {
Try changing
尝试改变
$this->load->model('Product'); $this->load->model('Company');
to
到
$this->load->model('product'); $this->load->model('company');
notice the lower case model names.
注意小写的型号名称。
Just tried it here and got the same error as you.
刚刚在这里尝试并得到与您相同的错误。
尝试为您的模型命名:
$this->load->model('Company', 'Company');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.