0

CI tank_auth ライブラリを使用してユーザー登録フォームを作成し、tank_auth に含まれていない新しいフィールドを追加する必要があります。

このTank Auth Adding Fieldsを参照しましたが、疑問を解決するのに役立ちません。

たとえば、登録中に「 Name 」フィールドを追加したいのですが、ビューとfunction register()コントローラーで作成しました。テーブルに入れたい場合を除いて正常に機能しuser_profiles、 という列を作成し、name次に tank_auth モデルのユーザーに作成しました。 php、以下のメソッドを見つけて追加しました:

private function create_profile($user_id, $name)
{
    $this->db->set('user_id', $user_id);
    $this->db->set('name', $name);
    return $this->db->insert($this->profile_table_name);
}

登録を実行すると、エラーは発生しませんでした。テーブルを確認すると、nameフィールドが挿入されていないため、にパラメーターが渡されていない可能性があります$name。これが私の問題です。この関数にパラメーターをどこに渡すことができますか?

このライブラリの経験のある人が私の疑問を解消してくれることを願っています。

ありがとう。

解決:

@Joan-Diego Rodriguezは、登録プロセス中に tank_auth の user_profiles テーブルにフィールドを追加する方法について非常に優れた実践を行っています。

CodeIgniter: Tank_auth を使用してフィールドを user_profiles データベースに渡す

これが同じ解決策を探している人に役立つことを願っています。

4

1 に答える 1

0

こんにちは、私はすでにこの問題に遭遇しました。私の解決策は簡単です

ユーザーの作成 -> 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;
}
于 2013-09-18T09:27:09.183 に答える