【发布时间】:2014-10-15 05:21:17
【问题描述】:
我正在使用 cakephp (2.4.7) 进行开发,但表单操作链接有问题。
我有一个带有编辑操作的 usersController。
public function edit($id = null, $slug = null) {
if (!$id) {
throw new NotFoundException(__('Invalid User'));
}
$user = $this->User->findById($id);
if (!$user) {
throw new NotFoundException(__('Invalid User'));
}
if ($this->request->is(array('post', 'put'))) {
// Do stuff here
}
// Fill the form
if (!$this->request->data) {
$this->request->data = $user;
}
}
使用此代码表单 ($this->create->('User'));在编辑视图中正确填写。但我在编辑视图中有另一个表单。
喜欢:
echo $this->Form->create(null, array(
'url' => array('controller' => 'useraddresses', 'action' => 'add')
));
echo $this->Form->input('searchvalue');
echo $this->Form->hidden('country');
echo $this->Form->hidden('city');
echo $this->Form->end('save');
当我单击此表单中的发送按钮时,页面链接到 /useraddresses/add/2(2 是用户的 ID) 我已经用 firebug 调试了表单,并且在 action 参数中也是 /useraddresses/add/2。
我怎样才能解决这个问题?我会将表单发送到 /useraddresses/add,不带任何参数。
如果我在编辑操作中删除这段代码,则操作链接正确,但我的第一个表单没有填写。
// Fill the form
if (!$this->request->data) {
$this->request->data = $user;
}
【问题讨论】:
-
// Input fields and Form->end('Send');???在此处粘贴您的输入字段代码