こんにちは、私はすでにこの問題に遭遇しました。私の解決策は簡単です
ユーザーの作成 -> user_profiles の作成 -> user_profiles の更新
TAモデルの「ユーザー」に移動して、このメソッド/関数を追加してください
function update_user_profile($user_id, $data)
{
$this->db->where('user_id', $user_id);
$this->db->update($this->profile_table_name, $data);
}
auth.php のコピーを作成し (念のため)、register メソッドでいくつかの調整を行います (次のように) 。ここに、元のコードがいくつか追加されていることに注意してください(私は私のものを変更しました)。
if ($this->form_validation->run()) {
// validation ok
if (!is_null(<here is some more code>)) {
$user_data = array(
'first_name' => $this->form_validation->set_value('first_name'),
'last_name' => $this->form_validation->set_value('last_name'),
);
//$this->load->model('tank_auth/users');
$this->users->update_user_profile($data['user_id'], $user_data); //update happens
} else {
$errors = $this->tank_auth->get_error_message();
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
}
}
編集
してユーザーを取得します。例に示すように、SQL JOIN を使用する必要があります (追加の first_name/last_name を使用)。
すべてのユーザーを取得し、これを users モデルに入れます
function get_all_users() {
$this->db->select('users.id, users.username, users.activated, users.banned, users.ban_reason, user_profiles.id as up_id, user_profiles.first_name, user_profiles.last_name');
$this->db->from('users');
$this->db->join('user_profiles', 'users.id = user_profiles.user_id');
return $this->db->get()->result();
}
1 人のユーザーを取得します (where 句を追加しただけです)
function get_ser($id){
$this->db->select('users.id, users.username, users.activated, users.banned, users.ban_reason, user_profiles.id as up_id, user_profiles.first_name, user_profiles.last_name');
$this->db->from('users');
$this->db->join('user_profiles', 'users.id = user_profiles.user_id');
$this->db->where('users.id', $id);
$q = $this->db->get();
return ($q->num_rows() > 0) ? $q->result()[0] : FALSE;
}