I know this question has been asked many times but none of the answers are fixing my problem. First of all let me show where I have setFlash and echo $this->Session->flash().
This is my add function:
if(!empty($this->request->data))
{
$friend_id = $this->request->data['User']['id'];
$user_id = $this->Auth->User('id');
$already_friends = $this->Group->findByIdAndFriend($user_id, $friend_id);
if($already_friends)
{
$this->Session->setFlash(__('You are already friends', true));
}
else
{
$this->Group->create();
$data = array($user_id, $friend_id);
if($this->Group->save($data))
{
$this->Session->setFlash(__('You are now friends', true));
}
else {
$this->Session->setFlash(__('Failed to add friend. Please try again', true));
}
}
$this->redirect(array('action' => 'index'));
This is my layout, the necessary part of it:
<div id="header">
<?php echo $this->Html->image('connect.jpg', array('alt' => 'My Image', 'id' => 'headerImage')) ?>
<div id="headerNavMenu">
<div name="navTab" class="menuTab">
<?php echo $this->Html->link('Me', array('controller' => 'users', 'action' => 'view', CakeSession::read("Auth.User.id")), array('class' => 'tabName')) ?>
</div>
<div name="navTab" class="menuTab">
<?php echo $this->Html->link('My Schedule', array('controller' => 'newSchedules', 'action' => 'index'), array('class' => 'tabName')) ?>
</div>
<div name="navTab" class="menuTab">
<?php echo $this->Html->link('My Group', array('controller' => 'groups', 'action' => 'index'), array('class' => 'tabName')) ?>
</div>
<div name="navTab" class="menuTab">
<a href="#" class="tabName">Settings</a>
</div>
</div>
<div id="login">
<?php echo CakeSession::read("Auth.User.firstName").' '.CakeSession::read("Auth.User.lastName").' ' ?>
<?php echo $this->Html->link('logout', array('controller' => 'users', 'action' => 'logout')) ?>
</div>
</div>
<div id="mainContent">
<?php echo $this->Session->flash(); ?>
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->fetch('content') ?>
</div>
</div>
Besides the fact that no flash messages show up, it also seems like the validation criteria is not being checked for models since specific messages don't show up either.
I am new at cakePHP but I have been following the blog tutorial to do most of my work. The flash messages used to work, but now it doesn't work for even models it used to.
Here are my validations:
public $validate = array(
'first_name' => array(
'required' => array(
'rule' => array('notempty'),
'message' => 'First Name cannot be blank',
'allowEmpty' => false,
'required' => true
)
),
'last_name' => array(
'required' => array(
'rule' => array('notempty'),
'message' => 'Last Name cannot be blank',
'allowEmpty' => false,
'required' => true
)
),
'email' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Email cannot be blank',
'allowEmpty' => false,
'required' => true
),
'valid' => array(
'rule' => array('email', true),
'message' => 'This is not a valid email',
'required' => true
),
'unique' => array(
'rule' => array('isUnique'),
'message' => 'This email already exists',
'required' => true
)
),
'password' => array(
'required' => array(
'rule' => array('notempty'),
'message' => 'Password cannot be blank',
'allowEmpty' => false,
'required' => true
),
'valid' => array(
'rule' => array('minlength', 6),
'message' => 'Password has to be at least 6 characters',
'required' => true
),
'password_has_to_be_alphanumeric' => array(
'rule' => 'alphanumeric',
'message' => 'Password has to be alphanumeric',
'required' => true
)
)
);