CakePHP:“GET”表单在提交后不会自动填充表单字段
发布时间:2020-12-13 17:23:44 所属栏目:PHP教程 来源:网络整理
导读:我正在使用Cake 2.3.0.如果我使用POST提交表单,则所选表单字段会结束,但如果我使用GET提交表单,则所有表单字段都将返回其默认值. 有没有办法让GET提交像POST一样工作? 这是我的控制器: class ListingsController extends AppController { public function
我正在使用Cake 2.3.0.如果我使用POST提交表单,则所选表单字段会结束,但如果我使用GET提交表单,则所有表单字段都将返回其默认值.
有没有办法让GET提交像POST一样工作? 这是我的控制器: 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()); } } 这是我的观点. 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; 不是我的电脑后面测试它(像往常一样,哈哈),但应该可行. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |