我想在同一个控制器中运行多个模型,但它显示在错误
之下严重性:注意
消息:未定义属性:主页:: $ Company
文件名:controllers / Home.php
行号: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);
}
}
//公司模式
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;
}
}
//产品型号
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;
}
}
答案 0 :(得分:1)
$models = array(
'menu_model' => 'mmodel',
'user_model' => 'umodel',
'admin_model' => 'amodel',
);
foreach ($models as $file => $object_name)
{
$this->load->model($file, $object_name);
}
答案 1 :(得分:1)
您的模型以
开头 class Company extends CI_Controller {
他们应该
class Company extends CI_Model {
<击> 尝试更改
$this->load->model('Product');
$this->load->model('Company');
到
$this->load->model('product');
$this->load->model('company');
注意小写的模型名称。只是在这里试了一下,得到了和你一样的错误。
击>
答案 2 :(得分:0)
尝试为您的模特命名:
addMibCompiler(mibBuilder, sources=['http://mibs.snmplabs.com/asn1/@mib@'], destination='/home/krish/mibs')