cakephp表单操作链接
我正在使用CakePHP2.4.7进行开发,但表单操作链接有问题 我有一个带有编辑操作的usersControllercakephp表单操作链接,php,cakephp,Php,Cakephp,我正在使用CakePHP2.4.7进行开发,但表单操作链接有问题 我有一个带有编辑操作的usersController public function edit($id = null, $slug = null) { if (!$id) { throw new NotFoundException(__('Invalid User')); } $user = $this->User->findById($id); if (!$user) {
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”;在“编辑”视图中,正确填充。但我在编辑视图中有另一个表单
比如:
当我单击此表单中的发送按钮时,指向/useraddresses/add/2的页面链接是用户的id
我已经用firebug调试了表单,在操作参数中也是/useraddresses/add/2
我怎么能在这件事上得逞呢?我将不带任何参数地将表单发送到/useraddresses/add
如果我在编辑操作中删除这段代码,则操作链接正确,但我的第一张表单没有填写
// Fill the form
if (!$this->request->data) {
$this->request->data = $user;
}
使用下列内容
if(empty($this->data) )
{
if (!$this->request->data) {
$this->request->data = $user;
}
}
而不是你
if (!$this->request->data) {
$this->request->data = $user;
}
//输入字段和表单->结束“发送”???粘贴输入字段代码无效,第二个表单仍然使用=>echo$this->form->create'searchUsers',array'url'=>array'controller'=>useraddresses',action'=>add'等链接到/useraddresses/add/2,而不是/useraddresses/addtry;为fornmIt命名可能是session,也可能是jquery,在url中添加/追加userid
if (!$this->request->data) {
$this->request->data = $user;
}