PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] CakePHP 3.x How to detect the specific Flash messages?

 February 21, 2022     cakephp, cakephp-3.0     No comments   

Issue

I have 8 different Flash elements.

4 of them are like these:

growl_success growl_error growl_info growl_warning

The other 4 are: alert_success alert_error alert_info alert_warning

I want to make it flexible so that at the Controller end, I can freely switch between any of these 8.

The problem is I want the <?= $this->Flash->render() ?> to be at different places in the layout.ctp for growl type messages compared to alert type messages.

Is there a way I can do something like

<?php if ($this->Flash->startsWith('growl') : ?> <?= $this->Flash->render() ?> <?php endif; ?>

or

<?= $this->Flash->renderGrowl(); ?>


Solution

I think you can use the 'key' options when setting the message

in your controller

$this->Flash->alert_success(__('Alert success!!'), [
                'plugin' => 'PluginName', 'key' => 'alert']);

or alternatively

$this->Flash->growl_success(__('The project has been saved.'), [
                'plugin' => 'PluginName', 'key' => 'growl']);

in your layout in two different positions

<?= $this->Flash->render('growl'); ?>

...

<?= $this->Flash->render('alert'); ?>


Answered By - arilia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing