我正在使用 Cake 2.3.0。如果我使用 POST
提交我的表单,则选定的表单字段会保留,但是如果我使用 GET
提交我的表单,所有表单字段都会返回到它们的默认值。
有没有办法让 GET
提交像 POST
一样工作?
这是我的 Controller :
class ListingsController extends AppController {
public function results() {
$conditions = array(
'Listing.Beds >=' => $this->request->query['beds'],
'Listing.ListingStatus >=' => $this->request->query['status'],
);
$this->paginate = array(
'conditions' => $conditions,
);
$this->set('listings', $this->paginate());
}
}
这是我的 View 。
echo $this->Form->create(null, array(
'controller' => 'listings',
'action' => 'results',
'type' => 'get'
));
echo $this->Form->input('name');
$beds = array('1' => '1+', '2' => '2+', '3' => '3+', '4' => '4+', '5' => '5+');
echo $this->Form->input('beds', array('options' => $beds));
$status = array('Active' => 'Active', 'Pending' => 'Pending', 'ActivePending' => 'Active and Pending');
echo $this->Form->input('status', array('options' => $status));
echo $this->Form->end('Update');
所以基本上,如果我将 'type' => 'get'
更改为 'type' => 'post'
它就可以正常工作。但我需要能够通过 GET
执行此操作。
谢谢
最佳答案
我同意这很烦人(IMO CakePHP 应该足够聪明,可以根据“类型”自动确定从“何处”获取数据)。
您必须将请求的“查询”复制到请求的“数据”;
$this->request->data = $this->request->query;
不在我的电脑后面测试它(像往常一样,哈哈),但应该可以工作。
关于php - CakePHP: "GET"表单在提交后不自动填充表单字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15751544/