[英]Codeigniter: how to call multiple model function in single controller function in codeigniter
I am new to coidigniter. 我是coidigniter的新手。
If I am calling single model method from controller function then its working fine. 如果我从控制器函数中调用单个模型方法,则其工作正常。
If I amt try to call more than one model function from single model, through single controller function, then I get 如果我尝试通过单个控制器功能从单个模型调用多个模型功能,那么我得到
Fetal Error:Call to a member function result() on Boolean 胎儿错误:以布尔值调用成员函数result()
my code look like this 我的代码看起来像这样
controller.php controller.php
public function get_details(){
$this->my_model->get_company(); //first call
$this->my_model->get_employee(); //second call
}
my_model.php my_model.php
public function get_company(){
$qry="CALL get_company_details";
$result=$this->db->query($qry);
foreach($result->result() as $row){
$data[]=$row;
}
return $data;
}
public function get_employee(){
$qry="CALL get_employee_details";
$result=$this->db->query($qry);
foreach($result->result() as $row){
$data[]=$row;
}
return $data;
}
Can I call like that. 我可以这样打吗 Please help me... 请帮我...
Simple typo: 简单的错字:
Change 更改
function get_company(){
to 至
function get_employee(){
You have defined same function twice. 您已经定义了两次相同的功能。
Make sure your database connection is ok in application/config/database.php 确保在application / config / database.php中数据库连接正常
$data = array();
$qry="SELECT * FROM . . . . ."; // your query
$result=$this->db->query($qry);
if($result->num_rows() > 0){
foreach($result->result() as $row){
$data[]=$row;
}
}
return $data;
Replace 更换
$result=$this->db->query($qry);
foreach($result->result() as $row){
$data[]=$row;
}
return $data;
to 至
return $result->result_array();
That should solve your problem. 那应该解决您的问题。 You can check result_array() section of CodeIgniter documentation. 您可以检查CodeIgniter文档的result_array()部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.