2012-06-29 85 views
0

我使用Codeigniter框架+ Tank_Auth注册库。他们的工作很好,但我只需要更改注册表。使用Codeigniter + Tank Auth的电子邮件创建用户名

我想从电子邮件地址生成用户名,而不是从注册表中获取用户名。我添加了一个简单的函数库/ Tank_auth.php文件。这里是我的用户名发生器功能:

function _create_username_from_email($email) 
{ 
$user = strstr($email, '@', true); // As of PHP 5.3.0 
return $user; 
} 
  1. 请让我知道我需要运行我的功能,并将其写入到数据库中。

  2. 我还需要从注册表中删除用户名字段。所以我需要我可以通过我的控制器中的用户名字段的表单验证。

如果你们中的任何一位能够帮助我解决这些问题,我将非常高兴。

感谢

回答

1

在行121application/models/tank_auth/users您有:

/** 
* Create new user record 
* 
* @param array 
* @param bool 
* @return array 
*/ 
function create_user($data, $activated = TRUE) 
{ 
    $data['created'] = date('Y-m-d H:i:s'); 
    $data['activated'] = $activated ? 1 : 0; 

    if ($this->db->insert($this->table_name, $data)) { 
     $user_id = $this->db->insert_id(); 
     if ($activated) $this->create_profile($user_id); 
     return array('user_id' => $user_id); 
    } 
    return NULL; 
} 

就在if ($this->db->insert($this->table_name, $data)) {插入前:

$data['username'] = strstr($data['email'], '@', true); 

附: 我希望你了解它,但以防万一 - 如果你有两个或更多用户使用同一个电子邮件的用户名部分,如[email protected][email protected],他们都将具有相同的用户名,这可能会导致意外的行为。

相关问题