我收到错误:当i时调用未定义的函数login() 调试($这 - >验证的登录());
当我点击登录我的会员登录时,它会进入“用户/登录”页面 我曾经有过UserController,但现在我删除了它。
会员模特:
App::uses( 'AppModel' , 'Model' );
App::uses('SimplePasswordHasher','Controller/Component/Auth');
class Member extends AppModel {
public function beforeSave( $options = array() ) {
if( isset( $this->data[$this->alias]['password'] ) ) {
$passwordhasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordhasher->hash( $this->data[$this->alias]['password'] );
}
return true;
}
}
MembersController:
public function login() {
if( $this->request->is('post') ) {
debug($this->Auth-login());
if( $this->Auth->login() ) {
return $this->redirect( $this->Auth->redirect() );
}
$this->Session->setFlash( __( 'Invalid username/password' ) );
}
}
login.ctp
<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('Member'); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>
这是我的AppController:
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'members',
'action' => 'profile'
),
'logoutRedirect' => array(
'controller' => 'members',
'action' => 'index'
)
),
'DebugKit.Toolbar'
);
我想在members / login
之后重定向到成员/个人资料页面答案 0 :(得分:0)
当您尝试使用Member
模型而不是默认User
模型时,您应该让Cakephp了解这一点 -
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'members',
'action' => 'profile'
),
'logoutRedirect' => array(
'controller' => 'members',
'action' => 'index'
),
'authenticate' => array(
'Form' => array(
'userModel' => 'Member'
)
)
),
'DebugKit.Toolbar'
);