gpt4 book ai didi

php - 数据从模型到 Controller 再返回到模型

转载 作者:行者123 更新时间:2023-11-30 01:35:01 25 4
gpt4 key购买 nike

<?php //controller
function notif()
{
$condition = $this->business_model->get_condition();
$this->data['query'] = $this->business_model->data_pagination_admin($condition);
$this->load->view('student_result',$this->data);
}
?>

<?php //model
function get_condition()
{

$this->db->select('condition');
$this->db->from('staff');
$query = $this->db->get();
return $query->result_array();
}

function data_pagination_admin($condition)//notif function
{
//...........
$this->db->where('flag','n');
//$user_id = $this->session->userdata('condition');
$this->db->where($condition,$user);//notice parameter condition
$this->db->order_by('next_date','asc');
$query = $this->db->get('student',10,0);
return $query->result_array();
}

/*im getting error :"Unknown column '0' in 'where clause'

SELECT * FROM (`student`) JOIN `status_table` ON `student`.`stud_id` =
`status_table`.`stud_id` WHERE `status_table`.`next_date` > '2013-06-09 23:59:59'
AND `flag` = 'n' AND **`0` = Array ORDER** BY `next_date` asc LIMIT 10"*/


?>

1.im从模型获取值到 Controller 并将其传递到 Controller 到另一个功能但出现错误。

2.controller->get_condition->controller->data_pagination_admin()

3.获取条件函数将仅返回一个字符串,仅此而已

最佳答案

get_condition当前返回一个数组;尝试下面的代码:

function get_condition()
{
$user = $this->session->userdata('user_id');
$this->db->select('condition');
$this->db->from('staff');
$this->db->where('user_id',$user );
$query = $this->db->get();
$result = $query->row_array();
return $result['condition'];
}

编辑:看起来 where 子句中的 $user var 也是一个数组。

关于php - 数据从模型到 Controller 再返回到模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17021178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com