gpt4 book ai didi

CakePHP:找不到 FlashComponent

转载 作者:行者123 更新时间:2023-12-02 16:46:38 25 4
gpt4 key购买 nike

我正在使用 CakePHP 2.6 并尝试遵循简单的身份验证教程。我正在为我的 Auth->User 使用另一个模型 Account。在我的 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 {

}

现在我知道我目前在 app\Controller\Component 中没有 FlashComponent.php 文件,我是否应该实际将其添加到那里?我在教程中没有看到任何有关它的内容。

谢谢!

应用 Controller

    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(); ?>

最佳答案

FlashComponent 已在 v2.7 中添加到 CakePHP 中。对于之前的版本,您需要使用 SessionComponent 并在 Controller 中使用 $this->Session->flash() 来设置 Flash 消息。

关于CakePHP:找不到 FlashComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34079853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com