【发布时间】:2014-03-17 17:10:59
【问题描述】:
我正在尝试使用 Yii 创建一个简单的登录 这是我的身份验证控制器
class AuthController extends Controller
{
/**
* Declare class-based actions.
*/
public function actionLogin()
{
$model = new LoginForm;
$post = Yii::app()->request->getPost('LoginForm');
// If form is submitted
if($post) {
$identity = new UserIdentity($post['username'], $post['password']);
echo $identity->testing();
if($identity->authenticate()) {
echo 'yes';
} else {
echo 'no';
}
exit;
}
$this->render('login', array('model' => $model));
}
}
这是我的用户身份
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{ echo 'testing';
$user = LoginForm::model()->findByAttributes(array('username' => $this->username));
if(is_null($user)) {
%this->errorCode=self::ERROR_USERNAME_INVALID;
} else if($user->password != $this->password) {
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
function getId()
{
return $this->_id;
}
}
我提到了 echo 'yes' 和 echo 'no' 但两者都没有显示。如何纠正它
【问题讨论】:
标签: php yii yii-components