use*_*292 3 cakephp cakephp-2.x cakephp-2.6
我正在使用CakePHP 2.6并尝试遵循简单的身份验证教程.我使用的另一种模式Account为我的Auth->User.Flash在我的AppController中添加组件后 - 我在所有页面上看到错误消息:
Error: FlashComponent could not be found.
Error: Create the class FlashComponent below in file: app\Controller\Component\FlashComponent.php
<?php
class FlashComponent extends Component {
}
Run Code Online (Sandbox Code Playgroud)
现在我知道我目前没有FlashComponent.php文件app\Controller\Component,我应该在那里实际添加吗?我在教程中没有看到任何关于它的内容.
谢谢!
AppController的
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');
}
Run Code Online (Sandbox Code Playgroud)
Login.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(); ?>
Run Code Online (Sandbox Code Playgroud)
该FlashComponent加入的CakePHP在V2.7.对于以前的版本,您需要在控制器中使用SessionComponent和$this->Session->flash()设置闪存消息.
| 归档时间: |
|
| 查看次数: |
3222 次 |
| 最近记录: |