Alley Hector
Alley Hector

Reputation: 1

Set cookie with button in Cakephp

I feel like this should be a very common thing but I can't find any info on it. I'm trying to set a cookie in CakePhp 3 from a button in a view. (The idea is that you click that to agree to terms and then the banner asking you to agree will no longer appear once the cookie is set)

I've loaded the component in the controller

$this->loadComponent('Cookie');

And then made a function (so far at its most basic)

public function setGoCookie()
{
    $this->Cookie->write('goCookie');
}

But I can't figure out how to call this action from the button in the view.

Upvotes: 0

Views: 391

Answers (2)

tarikul05
tarikul05

Reputation: 1913

you can't set COOKIE directly by client side (like HTML or CSS). you must have to trigger in server side. you can do it by ajax request or form submitting . You can also use CakePHP Cell for loading any data

Upvotes: 0

floriank
floriank

Reputation: 25698

But I can't figure out how to call this action from the button in the view.

Use AJAX or create a link to that action and redirect back from there to where you came from.

Upvotes: 2

Related Questions