这是我的模型:
function get_name() {
$this->db->select('first_name');
$this->db->where('email', $this->session->userdata('email'));
$query = $this->db->get('users');
if($query->num_rows() == 1) {
return true;
}
}
这是我的 Controller 方法:
function show_name() {
$this->load->model('users_model');
$this->users_model->get_name();
}
以及将名称传递给 View 的方法:
function profile(){
$data['first_name'] = $this->show_name();
$this->load->view('members/template', $data);
}
我在 View 中看不到任何东西,我检查了我的查询并且它工作正常。有什么我想念的吗?
最佳答案
您需要更新您的代码。您需要从函数 get_name
first_name
function get_name() {
$this->db->select('first_name');
$this->db->where('email', $this->session->userdata('email'));
$query = $this->db->get('users');
if($query->num_rows() == 1) {
return $query->row()->first_name;
}
}
您还需要返回
函数show_name
的值
function show_name() {
$this->load->model('users_model');
return $this->users_model->get_name();
}
关于php - 无法在 codeigniter 下的 View 中打印数据库中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971863/