Laravel 4 表单::打开集合操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15450303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 Form::open set action
提问by Crinsane
I'm currently trying out Laravel 4 and I have created a resource controller. In the 'edit' function I'm building a form, which should post to the 'update' function.
我目前正在试用 Laravel 4 并且我已经创建了一个资源控制器。在“编辑”功能中,我正在构建一个表单,该表单应该发布到“更新”功能。
To create the form open tag I use the Form::open()
function which recently got added to Laravel 4 it seems.
But when I just do Form::open()
the action of the form is the current url and I can't figure out how to change the action.
为了创建表单打开标签,我使用了Form::open()
最近添加到 Laravel 4的功能。但是当我只是做Form::open()
表单的动作是当前的 url 时,我不知道如何改变动作。
I tried Form::open('clients/' . $client->id)
but this gives me the following error:
我试过了,Form::open('clients/' . $client->id)
但这给了我以下错误:
ErrorException: Catchable Fatal Error: Argument 1 passed to Illuminate\Html\FormBuilder::open() must be of the type array
ErrorException: Catchable Fatal Error: 传递给 Illuminate\Html\FormBuilder::open() 的参数 1 必须是数组类型
So I tried Form::open('[clients/' . $client->id)
. This doesn't generate an error, but now the form open tag is:
所以我试过了Form::open('[clients/' . $client->id)
。这不会产生错误,但现在表单打开标签是:
<form method="POST" action="http://boekhouding.dev/clients/1/edit" accept-charset="UTF-8" clients/1="clients/1">
<form method="POST" action="http://boekhouding.dev/clients/1/edit" accept-charset="UTF-8" clients/1="clients/1">
And I also tried it like this: Form::open(['action' => 'clients/' . $client->id])
but when I do it like this, the form open tag has no action at all.
我也这样尝试过:Form::open(['action' => 'clients/' . $client->id])
但是当我这样做时,表单打开标签根本没有任何动作。
So, does anyone know how to set the form action? Using a named route would be perfect, but even being able to set the action at all would be nice.
那么,有谁知道如何设置表单操作?使用命名路线将是完美的,但即使能够设置动作也很好。
回答by kok
You can use named route, controller action or simple url to set form action.
您可以使用命名路由、控制器操作或简单 url 来设置表单操作。
To set it via named route use:
要通过命名路由进行设置,请使用:
{{ Form::open(array('route' => array('route_name', $client->id))) }}
To set it via controller action use:
要通过控制器操作设置它,请使用:
{{ Form::open(array('action' => array('ClientController@update', $client->id))) }}
So the keyword action
does not reffer to 'action' parameter of form tag, but to controller action
所以关键字action
不是指表单标签的'action'参数,而是指控制器动作
And you can also use plain URL like this:
你也可以像这样使用普通的 URL:
{{ Form::open(array('url' => 'someurl')) }}
回答by Codeplus
@jeffrey_way tweeted about improving the new FormBuilder in Laravel 4. The following paste bucket link should help. It seems to be more about RESTful controllers, but relavant.
@jeffrey_way 发布了关于改进 Laravel 4 中新 FormBuilder 的推文。以下粘贴桶链接应该会有所帮助。它似乎更多是关于 RESTful 控制器,但相关。
Form action sensible defaults - paste bucket
I thought I read something about him coming out with a Forms tutorial tomorrow. If so, it might be found here net.tutsplus.com/?s=laravel
我想我读到了一些关于他明天发布表单教程的信息。如果是这样,可以在这里找到net.tutsplus.com/?s=laravel