[英]Laravel 4 Form Model not binding id correctly
I am binding a user model to a form and attaching the id. 我将用户模型绑定到表单并附加ID。 When i hit submit it places a character code (%7Bid%7D) into the form in place of the id.
当我点击提交时,它将字符代码(%7Bid%7D)放置在表单中以代替ID。 The model elements bind to the form properly otherwise.
否则,模型元素将正确绑定到表单。 If I use firebug to change that code to 1 then it fires fine so I know it is an issue with how the id is binding or set.
如果我使用firebug将该代码更改为1,那么它将正常运行,因此我知道id是如何绑定或设置的。
What am I doing wrong? 我究竟做错了什么?
I have the following code pieces: 我有以下代码段:
View 视图
{{ Form::model($user, array('route' => 'users.update', $user->id)) }}
Route that is being set in the form 表单中设置的路线
Route::post('users/{id}/update', array(
'uses' => 'UserController@update',
'as' => 'users.update'
));
Controller Method that calls the form (UserController) 调用表单的Controller方法(UserController)
public function edit($id)
{
//
$user = $this->user->find($id);
return View::make('users.edit')->with('user', $user);
}
从您说您得到%7Bid%7D
的事实来看,我没有看到表格的代码,而您错过了一组花括号。
I had a similar problem. 我有一个类似的问题。 It was down to a named route that required a parameter.
这取决于需要参数的命名路由。
Route::post('something/new/{id}', array(
'as' => 'something-new-post',
'uses' => 'SomeController@newFunction'
));
I was calling it using 我当时用
{{ URL::route("something-new-post") }}
with the intention of adding the variable later. 目的是稍后添加变量。 What I should have been doing is adding an extra parameter..
我应该做的是添加一个额外的参数。
{{ URL::route("something-new-post", $data) }}
live and learn.. 活到老,学到老..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.