所以我正在学习Yii框架,当你第一次创建sceleton应用程序时,内置的管理员/模拟帐户就有了这个功能.我想删除它们,因为即使在uplodet到我的网络服务器后我仍然可以使用它们登录.那么我在哪里可以删除它?
boo*_*dev 12
在文件夹protected/components /中,您将拥有一个文件UserIdentity.php,即出现这些默认登录的位置,您可以更改/删除它们.
您可以使用您的数据库对您的用户表进行身份验证,有点像这样:
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$record=User::model()->findByAttributes(array('username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($record->password!==md5($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record->id;
$this->setState('title', $record->title);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}
Run Code Online (Sandbox Code Playgroud)
请查看指南中的这篇文章.
在protected/components下你会找到UserIdentity.php,用户及其密码将在使用数组的authenticate函数中声明.
public function authenticate()
{
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
Run Code Online (Sandbox Code Playgroud)
有关如何在Yii中使用身份验证的更多具体信息可以在官方Yii文档的身份验证和授权子部分找到
| 归档时间: |
|
| 查看次数: |
9572 次 |
| 最近记录: |