I am trying to save data in the session with cakePHP. I have read the documentation and many examples online but I can't seem to save the data in the session.
In my controller I have added the session write function:
public function take(){
if(array_key_exists('option', $this->request->data)){
foreach($this->request->data['option'] as $cmd => $options){
foreach($options as $cmd => $option){
$buildCmnd = '-1 RENDERER*'.$this->request->data['Playlist']['layer'].'*TREE*$master*SCRIPT*INSTANCE*externalCommand SET '.$this->request->data['Playlist']['el'].' '.$cmd.' text={'.$option.'}';
$this->send($buildCmnd);
}
}
}
$this->Session->write('TakenCommand', array( $this->request->data['Playlist']['el'] ) );
$this->autoRender = false;
}
I am calling the action via jquery ajax:
$("#inputTake").click(
function()
{
jQuery.ajax({
type:'POST',
async: true,
cache: false,
url: '/Controller/take',
success: function(response) {
jQuery('#resultField').val(response);
},
data:jQuery('form').serialize()
});
return false;
}
);
Because I am using ajax, I created an element that I call to check the session. This is the contents of the element:
<pre>
<?php print_r($this->Session->read());?>
</pre>
But the session variable "TakenCommand" does not appear in the output.
I have added the Session component to the AppController.php file:
public $components = array('Session');
And I have changed the core.php file session default from "php" to "cake" and back, but neither seem to help.
Any suggestions would be greatly appreciated!
Some answer I have seen suggest to set 'checkAgent' => false in core.php but this doesn't help either. In CakePHP 1.x is was possible to set the security level to medium which would resolve the problem, but this option is not available in 2.x.