Cupcake フォーラム プラグインのログイン機能を動作させようとしています。
users_controller.php では、
ログイン関数の $user 変数が設定されていなかったため、エラーが発生していました。そのため、ログイン機能を次のように変更しました。
public function login() {
if (!empty($this->data)) {
$this->User->set($this->data);
$this->User->action = 'login';
//--------------code that i added--------------
$username=$this->data['User']['username'];
$password=$this->data['User']['password'];
$user=$this->User->find('all',array(
'condition'=>array(
'User.username'=>$username,
'User.password'=>$password
)));
print_r($user);
//------------------------------------------------------------------------
if ($this->User->validates()) {
if ($user == $this->Auth->user()) {
$this->User->login($user);
$this->Session->delete('Forum');
$this->redirect($this->Auth->loginRedirect);
}
else
echo('i\'m not auth user');
}
else
echo('not validated');
}
$this->Toolbar->pageTitle(__d('forum', 'Login', true));
}
print_r($user) は User モデルのすべてのユーザーを表示します。当然、ログインしたユーザーのデータのみを表示する必要があります。どうすればそれを達成できますか? 私は無知で、これは私を狂気に駆り立てています。