I am using CakePHP 2.6 and trying to follow along with the simple authentication tutorial. I am using another model Account
for my Auth->User
. After adding in the Flash
component in my AppController - I'm seeing the error message on all of my pages:
Error: FlashComponent could not be found.
Error: Create the class FlashComponent below in file: app\Controller\Component\FlashComponent.php
<?php
class FlashComponent extends Component {
}
Now I know that I currently do not have a FlashComponent.php file in app\Controller\Component
, am I supposed to actually add it there? I am not seeing anything in the tutorial about it.
Thank you!
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');
}
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(); ?>
The FlashComponent
was added to CakePHP in v2.7. For prior versions you need to use SessionComponent
and use $this->Session->flash()
in your controller to set flash messages.