2011-08-15 50 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小时用这个打破我的头。

相关问题