我正在使用 CakePHP 2.6 并尝试遵循简单的身份验证教程。我正在Account
为我的Auth->User
. 在我的 AppController 中添加Flash
组件后 - 我在所有页面上都看到了错误消息:
Error: FlashComponent could not be found.
Error: Create the class FlashComponent below in file: app\Controller\Component\FlashComponent.php
<?php
class FlashComponent extends Component {
}
现在我知道我目前没有 FlashComponent.php 文件app\Controller\Component
,我应该实际添加它吗?我在教程中没有看到任何关于它的内容。
谢谢!
应用控制器
public $components = array(
'Flash',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'accounts',
'action' => 'index'
),
'loginAction' => array(
'controller' => 'accounts',
'action' => 'login'
),
'logoutRedirect' => array(
'controller' => 'accounts',
'action' => 'login',
),
'authenticate' => array('Form' => array(
'userModel' => 'Account',
'passwordHasher' => 'Blowfish',
'fields' => array(
'username' => 'email',
'password' => 'token',
)
)
)
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
登录.ctp
<?php echo $this->Flash->render('auth'); ?>
<?php echo $this->Form->create('Account', array('action' => 'login')); ?>
<?php echo $this->Form->input('email', array('class' => 'form-control', 'type' => 'email', 'placeholder' => 'Email', 'label' => false)); ?>
<?php echo $this->Form->input('token', array('class' => 'form-control', 'type' => 'password', 'placeholder' => 'Password', 'label' => false)); ?>
<?php echo $this->Form->submit('Sign In', array('class' => 'btn btn-primary btn-block btn-flat')); ?>
<?php echo $this->Form->end(); ?>