Laravel 4 Form ::打开设定动作 [英] Laravel 4 Form::open set action

查看:93
本文介绍了Laravel 4 Form ::打开设定动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试用Laravel 4,并创建了一个资源控制器.在编辑"功能中,我正在构建一个表单,该表单应发布到更新"功能中.

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中添加的Form::open()函数. 但是当我只执行Form::open()时,表单的动作是当前的url,我不知道如何更改动作.

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('clients/' . $client->id),但这给了我以下错误:

I tried Form::open('clients/' . $client->id) but this gives me the following error:

错误异常:可捕获的致命错误:传递给Illuminate \ Html \ FormBuilder :: open()的参数1必须为数组类型

所以我尝试了Form::open('[clients/' . $client->id).这不会产生错误,但是现在表单打开标记为:

So I tried Form::open('[clients/' . $client->id). This doesn't generate an error, but now the form open tag is:

<form method="POST" action="http://boekhouding.dev/clients/1/edit" accept-charset="UTF-8" clients/1="clients/1">

我也这样尝试过:Form::open(['action' => 'clients/' . $client->id]),但是当我这样做时,表单打开标记根本没有任何作用.

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.

那么,有人知道如何设置表单操作吗?使用命名的路线将是完美的,但是即使能够完全设置动作也将是很好的.

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.

推荐答案

您可以使用命名的路由,控制器操作或简单的url来设置表单操作.

You can use named route, controller action or simple url to set form action.

要通过命名路线进行设置,请使用:

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))) }}

因此,关键字action 不代表表单标签的"action"参数,而是 controller action

您还可以像这样使用纯网址:

And you can also use plain URL like this:

{{ Form::open(array('url' => 'someurl')) }}

这篇关于Laravel 4 Form ::打开设定动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆