BlackAlpha
BlackAlpha

Reputation: 376

Set a variable in a Foundation's reveal modal - CakePHP

I'm trying to set a variable in a reveal modal with CakePHP. The reveal modal i'm using is with Zurb Foundation

I have to generate a code and display it. I have a HomeController with a generatecode() function. In my Home.ctp I have a div with reveal modal (cf. Basic section here) I have also a link button generate with that code :

echo $this->Html->Link('Unlock Link', array('action'=>'unlockpwd'), array('class' => 'button small', 'data-reveal-id' => 'modal_unlockpwd'));

Here is my action code :

function unlockpwd() {
        $this->set('code', $this->Function->generatePwdLock());
        $this->redirect($this->referer());
}

And in my Home.ctp, i just display $code in the reveal modal but i get an undefined variable error.

I think it's because i display the modal before i set $code.

How can I solve this problem ? I tried the setFlash, it works but the reveal modal seems better for the user.

Thanks for your help :)

Upvotes: 2

Views: 140

Answers (1)

TrueSkillZ
TrueSkillZ

Reputation: 307

You set 'code' as a variable and redirect away from the page so the variable is lost. Solution would be to do:

function unlockpwd() {
    $this->Session->write('Code', $this->Function->generatePwdLock());
    $this->redirect($this->referer());
}

where you want to see it:

echo $this->Session->read('Code'); 
$this->Session->delete('Code'); //if you want to show only once

Upvotes: 1

Related Questions