未从视图向控制器发送表单数据

问题描述 投票:0回答:1

因此,我尝试从cake的表单构建器中的表单发送一些数据,但是由于某些原因,当我打印出$this->data$this->request->data时,没有任何提交的数据显示出来>

我曾尝试自己创建表单并使用Cake的Form Builder,但我需要通过POST发送此数据。如果我将其作为GET参数发送,则会显示数据。

view.ctp

echo $this->Form->create(null, array('action' => 'downloadbgc', 'type' => 'get'));
echo $this->Form->input('userId', ['type' => 'text' , 'id' => 'userId', 'name' => 'userId', 'value' => $user->id]);
echo $this->Form->input('product_id', ['type' => 'hidden' , 'id' => 'product_id', 'name' => 'product_id', 'value' => $user->product_id]);
echo $this->Form->submit('Download PDF', array('class' => 'btn btn-icon btn-primary', 'title' => 'Download'));
 echo $this->Form->end();

controller.php

...
public function downloadbgc() {
    $this->autoRender = false;

    print_r("Data: ");
    print_r($this->data); die();
    }
}
...

打印出来时,我得到的是Data: Array()而不是Array('userId' => X, 'product_id' => Y),我很肯定这些值不为null,因为它们已打印到控制台。

因此,我试图从cake的表单构建器中的表单发送一些数据,但是由于某些原因,当我打印出$ this-> data或$ this-> request-时,没有显示正在提交的数据。 &...

forms cakephp-2.x
1个回答
0
投票

以正确的方式使用FormHelper的create():

© www.soinside.com 2019 - 2024. All rights reserved.