我正在使用expressionengine作为CMS,但希望覆盖新用户的核心验证。当有人注册为新用户时,系统会检查是否已经使用了screen_name。如果是,则抛出错误标志。
我已经找到了正在进行验证的代码部分,但我想更改它,以便不是抛出错误而是屏幕名称附加了一个空格和数字(一个高于计数值。
所以“John Smith”改为“John Smith 3”(假设数据库中有另外两个“John Smith”screen_names)。
如何修改此代码以实现此目的?
/** -------------------------------------
/** Is screen name taken?
/** -------------------------------------*/
if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
{
$query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");
if ($query->row['count'] > 0)
{
$this->errors[] = $LANG->line('screen_name_taken');
}
}
答案 0 :(得分:1)
if (strtolower($this->cur_screen_name) != strtolower($this->screen_name))
{
$query = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name = '".$DB->escape_str($this->screen_name)."'");
if ($query->row['count'] > 0)
{
$query2 = $DB->query("SELECT COUNT(*) AS count FROM exp_members WHERE screen_name LIKE '".$DB->escape_str($this->screen_name)."'");
$name = $DB->escape_str($this->screen_name).$query2->row['count'];
$this->errors[] = 'The screen name you choose is taken please use '.$name.' for your new screen_name);
}
}
玩得开心!