简体   繁体   中英

CakePHP 2.0+: Retrieving POST data from Js->submit form in controller

I am using $this->Js->submit to pass a value to my controller asynchronously and than update a div (id = #upcoming). Somehow I cannot save/retrieve the value of the field 'test' which is passed to my controller. Firebug tells me that the correct value is passed. What am I doing wrong?

View file (playlist.ctp):

echo $this->Form->create('Add', array('url' => array('controller' => 'Gods', 'action' => 'add')));
echo $this->Form->input('test');       
echo $this->Js->submit('Addddd', array(
'url' => array(
    'controller' => 'Gods',
    'action' => 'add'
),
'update' => '#upcoming'
));
echo $this->Form->end();

echo $this->Js->writeBuffer(array('inline' => 'true'));

Controller action:

public function add()
{
$this->autoLayout = false;
   $this->layout = 'ajax';
$link = $this->request->data['Add']['test'];
$this->set('test',$link);
}

And its view file (add.ctp):

<?php
echo $test;
?>

Thanks for your help!

have you tried pr($link) in the controller method? Or just send it to a log file if you prefer that. That way you can see if the data is received.

If so, I think there is nothing returned because of

 $this->autoLayout = false;

Try it without this. It will still call the ajax layout instead of the default. Otherwise you have to manualy call the render function

$this->render('add');

EDIT As explained in the comments below, make sure your views are in the right place. (that would be the view folder associated with the controller)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM