如何在cakePHP中从输入表单向控制器传递id和值?
这是我的密码 查看(编辑.ctp): 这就是$This->request->data数组的外观:如何在cakePHP中从输入表单向控制器传递id和值?,php,cakephp,httprequest,cakephp-2.0,Php,Cakephp,Httprequest,Cakephp 2.0,这是我的密码 查看(编辑.ctp): 这就是$This->request->data数组的外观: 有没有办法在不必在控制器中构建阵列的情况下实现这一点?在视图/表单中单击“提交”时,正在寻找将id和值同时传递到请求中的方法。通过在我的ctp文件中添加这行代码找到了解决方案: <?php echo $this->Form->input('Answer.0.id', array('hidden' => true)) ?> 因此,这里您可以使用这种方式 在控制器中:
有没有办法在不必在控制器中构建阵列的情况下实现这一点?在视图/表单中单击“提交”时,正在寻找将id和值同时传递到请求中的方法。通过在我的ctp文件中添加这行代码找到了解决方案:
<?php echo $this->Form->input('Answer.0.id', array('hidden' => true)) ?>
因此,这里您可以使用这种方式 在控制器中:
$data = $this->Post->findById($id);
if ($this->request->is(array('post', 'put'))) {
$this->Answer->id = $id;
if ($this->Answer->save($this->request->data)) {
$this->Session->setFlash('Answer Editted');
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash('Answer Not Editted');
}
if (!$this->request->data) {
$this->request->data = $data;
在视图文件中,传递隐藏字段ID:
echo $this->Form->input('id', array('type' => 'hidden'));
$data = $this->Post->findById($id);
if ($this->request->is(array('post', 'put'))) {
$this->Answer->id = $id;
if ($this->Answer->save($this->request->data)) {
$this->Session->setFlash('Answer Editted');
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash('Answer Not Editted');
}
if (!$this->request->data) {
$this->request->data = $data;
echo $this->Form->input('id', array('type' => 'hidden'));