2011-08-15 49 views
2

我一直在使用Tank Auth庫,並且對此有疑問。我在註冊表中添加了兩個字段:first_name和last_name,我試圖找出爲什麼它沒有插入user_profiles頁面。Tank Auth添加字段

有了更新的代碼我得到這個錯誤:

A PHP Error was encountered

Severity: Warning

Message: Missing argument 5 for Tank_auth::create_user(), called in /home/xtremer/public_html/kowmanager/application/controllers/auth.php on line 136 and defined

Filename: libraries/Tank_auth.php

Line Number: 162 A PHP Error was encountered

Severity: Notice

Message: Undefined property: Tank_auth::$users

Filename: libraries/Tank_auth.php

Line Number: 188

Fatal error: Call to a member function UpdateProfileInfo() on a non-object in /home/xtremer/public_html/kowmanager/application/libraries/Tank_auth.php on line 188

更新的代碼:

Auth Controller

Tank Auth Library

Users Model

任何想法對我是什麼做wr現在呢?

我會在這個50點的賞金,但我不能讓鏈接上來,所以有一個賞金。

+0

您可以重新格式化該代碼,以便它清晰可辨嗎? –

+0

是更好嗎? –

+0

感謝您的補充修復。 –

回答

8

什麼,你應該做的是把你想要的兩列在user_profiles表,然後添加一個功能到models/tank_auth/users.php的東西,如:

function UpdateProfileInfo ($userID, $firstname, $lastname) 
{ 
    return $this->db->update('user_profiles', array('firstname'=>$firstname, 'lastname'=>$lastname), array('user_id' => $userID)); 
} 

然後更換(以/libraries/Tank_auth.php
function create_user($username, $email, $password, $email_activation)
隨着
function create_user($username, $email, $password, $email_activation, $userInfo)

然後正下方(在/libraries/Tank_auth.php
if (!is_null($res = $this->ci->users->create_user($data, !$email_activation))) { 添加
$this->users->UpdateProfileInfo($userInfo["firstname"],$userInfo["lastname"]);

然後更換(以/controllers/auth.php

 if ($this->form_validation->run()) {        // validation ok 
      if (!is_null($data = $this->tank_auth->create_user(
        $use_username ? $this->form_validation->set_value('username') : '', 
        $this->form_validation->set_value('email'), 
        $this->form_validation->set_value('password'), 
        $email_activation))) {         // success 

有:

$userInfo["firstname"] = $this->form_validation->set_value("firstname"); 
$userInfo["lastname"] = $this->form_validation->set_value("lastname"); 

if ($this->form_validation->run()) {        // validation ok 
    if (!is_null($data = $this->tank_auth->create_user(
      $use_username ? $this->form_validation->set_value('username') : '', 
      $this->form_validation->set_value('email'), 
      $this->form_validation->set_value('password'), 
      $email_activation, $userInfo))) {         // success 

這不是測試,但它應該工作,告訴我如何不言而喻
最大

+0

庫中已經有一個函數來處理它。你對這個圖書館有什麼經驗嗎? –

+0

我已更新我的代碼以顯示處理該庫時已包含的內容。它沒有插入user_profiles頁面。 –

+2

我確實對庫很熟悉,而且我知道有一個createprofile函數。我建議把它放在一個不同的函數中,這樣如果用戶改變了他們的信息(比如說你在這個函數中還包含了城市/州的信息),你可以重用它。 – Ben

2

我注意到有兩件事情:

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

$data是一個數組,我假設你SHOULDfirst_namelast_name這裏(你沒有)。

另外TANK AUTH要求您更新您需要的配置文件數據庫模式的列(您是否這樣做?沒有提及)。

要解決上面的代碼,你就需要在陣列($data)在像這樣通過更多的細節:

$data['first_name'] = "Bob"; 
$data['last_name'] = "Smith"; 

create_profile($user_id, $data); // which would then use the first & last names 

不,我要保持談話繼續下去關於這一點,但。 ..*

你需要做的正是我向您展示:

  • 定義2個變量(第一&姓),並將其傳遞給create_profile FN。
  • 正確使用變量(不要使用$data[0]即SLOPPY,如果這就是你所說的數組值,那麼做$data['first_name']。沒有理由要馬虎,做$ data [0] - 在你的數組的關鍵值)。
  • 它不難,閱讀你的代碼(理解它,如果你沒有退後一步,並試圖逐行分解發生了什麼,我感到你不知道這些函數是什麼這樣做)。
+0

我沒有更新數據庫Jakub,問題在於我把$ data ['first_name'] part –

+0

嗯,很簡單,在調用fn create_profile($ userid,$ data)的地方,所以我在'create_user()'fn中看到它。 – Jakub

+0

所以你說它應該是私人函數create_profile($ user_id,$ data) \t { \t \t $ this-> db-> set('user_id',$ user_id); $ this-> db-> set('first_name',$ data [0]); $ this-> db-> set('last_name',$ data [1]); \t \t return $ this-> db-> insert($ this-> profile_table_name); \t}因爲我不知道。 –

1

檢查庫中的Tank_auth文件,還有另一個「create_user」函​​數需要修改。正確管理變量。 3小時用這個打破我的頭。

相關問題