Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify Cakephp Configure with Ajax

i'm realizing an admin panel and i need to toggle an option on/off. Everything works fine, except for the Configure::write() method that looks like if it's not permanent. Here is the ajax handler.

        case ("toggle_button"):
        if($_POST['status']=="On"){

            Configure::write('tag_system',0);


            die("Off");

        }
        elseif($_POST['status']=="Off"){
            Configure::write('tag_system',1);

            die("On");

        }


        break;

If i try

die(Configure::read('tag_system'));

it contains the correct value but when i reload the page, the value is missing. It's not set in the general config file but when i did, the behavious was similar but instead of a blank value, Configure::read returned the value in the config file.

How should i handle this?

like image 570
Chobeat Avatar asked Aug 12 '26 05:08

Chobeat


1 Answers

The Configure class writes values you pass to it into memory which are then only available during that request.

If you need to use the value in subsequent requests, which it sounds like you do, then you need to write the value to session.

# write
$this->Session->write('tag_system', 1);

# read
$this->Session->read('tag_system');
like image 197
Moz Morris Avatar answered Aug 13 '26 19:08

Moz Morris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!