0
CakePHP 2.0
アプリケーションにログインしようとしていますが、ログインエラーが発生します。公式documentationで と私はパスワードをハッシュする方法を読んだが、私はまだログインエラーを取得し、ここで私はそれをやった方法ですtutorial:パスワードと認証コンポーネントをハッシュする
// Users Model
public function beforeSave ($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
// Users Controller
public $components = array ('Acl', 'Session',
'Auth' => array (
'authenticate' => array (
// login e logout sono di default i seguenti controller e views
// 'loginRedirect' => array ('controller' => 'users', 'action' => 'login'),
// 'logoutRedirect' => array ('controller' => 'users', 'action' => 'logout'),
'Form' => array (
'fields' => array (
// il valore default
'username' => 'email'
),
'scope' => array (
'User.active' => 1
)
)
),
'authError' => 'Login error message I get'
));
public function login() {
if ($this->request->is('post')) { // if the request came from post data and not via http (useful for security)
// the password is hashed in User Model in beforeSave method as read on documentation
// debug ($this->data);
if ($this->Auth->login()) {
$id = $this->Auth->user('id');
return $this->redirect(array('controller'=>'users', 'action'=>$id, $this->Auth->user('username')));
} else {
$this->Session->setFlash('Login error message', 'default', array(), 'auth');
}
}
}
私はデータをデバッグしようとした場合
// the view login.ctp
echo $this->Form->text('User.email', array('id'=>'email', 'value'=>'[email protected]'));
echo $this->Form->password('User.password', array('id'=>'password', 'value'=>'password'));
私はこれを取得:
// in the controller
debug($this->data);
// in the view
Array
(
[User] => Array
(
[email] => [email protected]
[password] => thepass // not hashed
)
)
私はいつもLogin error message
を取得するので、私はログインできません。どうすれば修正できますか?
ありがとうございました1)質問のエラーを更新しました。 | 2)sessionFlashを印刷しようとすると次のようになります:致命的なエラー:/public_html/site.com/app/View/Layouts/default.ctpの非オブジェクトのメンバ関数sessionFlash()を呼び出します。 3)私はこれを見てみましょう!ありがとう – vitto
(2)あなたのコントローラやAppControllerで '$ helpers'配列のヘルパー' Layout'を設定してください。 'public $ helpers = array(/ * others * /、 'Layout'、/ * others * /)'; – colares
多分あなたが話しているかもしれません: '<?php echo $ this-> Session-> flash();エコー$ this-> Session-> flash( 'auth'); ?> 'これは動作していますが、エラーを取得するために使用しています – vitto