我有一个用户模型和一个user_profile模型,我正在尝试使用以下函数获取特定用户和相关的user_profile。如果我注释掉它包含的include_related行并根据user_id获取用户但是如果我尝试使用include_related来提取用户配置文件字段,它只返回数据库中的第一个用户而不是基于user_id的用户。这里出了什么问题?
function edit_admin_user(){
//check user is logged in and has admin rights
$this->login_manager->check_login(1);
//get user id from the uri segment
$user_id = $this->uri->segment(3);
$user = new User();
$user->get_by_id($user_id);
//$user->include_related('user_profile', array('firstname','surname', 'telephone', 'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();
//set the content for the view partial (this is the actual content of the page)
$content_data['user'] = $user;
$data['content'] = $this->load->view('admin/edit_admin_user', $content_data, TRUE);
$data['page_title'] = 'Get Stuffed | Admin Area | Edit Admin User';
$this->load->view('admin/index', $data);
}
答案 0 :(得分:0)
本来应该有心理障碍:
$user = new User();
$user->where('id', $user_id);
$user->include_related('user_profile', array('firstname','surname', 'telephone', 'address1', 'address2', 'city', 'postcode'), TRUE, TRUE)->get();