Sunday, January 9, 2022

[FIXED] How to print the email after register in flash messages using cakephp3

Issue

<?php
public function add(){

// code 

      $this->Flash->activateUsers('Thank you for choosing our website', $this->request->getData('email'));

}

?>

then I create a file inside src\Template\Element\Flash\activate_users.ctp with the content below:

<div class="message success">
       <?= h($message) , $this->request->getData('email'); ?>
                  or
       <?= h($message) ?> <?=h($this->request->getData('email')) ?>
</div>

But after successfull filling up the form with no error it will just print this:

"Thank you for choosing our website"


Solution

In your controller:

$this->Flash->activateUsers('Thank you for choosing our website', [
    'params' => [
        'email' => $this->request->getData('email'),
    ]
]);

In your template:

<?= h($message) ?>, <?= h($params['email']) ?>

There's an example of this in the Flash component section of the manual.



Answered By - Greg Schmidt

No comments:

Post a Comment

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