【问题标题】:laravel 4 full documentation Form::openlaravel 4 完整文档 Form::open
【发布时间】:2015-06-17 21:59:22
【问题描述】:

当我在 Laravel 4 API 中搜索时,例如:

Form::open(array $options = array())

我找不到可用选项的完整列表?在哪里可以找到?

http://laravel.com/api/4.1/Illuminate/Html/FormBuilder.html#method_open

谢谢,

【问题讨论】:

  • 在Illuminate/Html/FormBuilder.php中也找不到

标签: php laravel laravel-4


【解决方案1】:

具体选项请参见下面的链接,即methodactionfilesurlroute

http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#63

这里解释了它们的用法

http://laravel.com/docs/html#opening-a-form

您也可以添加您在 HTML 中使用的任何其他属性作为选项。

【讨论】:

    【解决方案2】:

    选项有:

    • 方法:POST、GET、PUT、PATCH、DELETE。最后三个方法被一个隐藏字段欺骗。
    • action:设置action='...' 属性。如果还有urlroute 选项,它们将被翻译成相应的 URL。否则,action 应该指向一个控制器动作路由。如果不存在,则该操作默认为当前 URL。
    • accept-charset:强制为 UTF-8
    • 文件:可以是true,如果存在文件上传,则将enctype = 'multipart/form-data' 附加到表单中。

    连同您希望添加的任何选项(如“id”、“enctype”或类似的)。

    【讨论】:

      【解决方案3】:

      你应该看看 laravel 官方文档

      http://laravel.com/docs/html

      【讨论】:

        【解决方案4】:

        看一下源码:https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php#L95

        一些复杂的形式:

        Form::open(['method' => 'put', 'action' => 'awesomeController@putForm', 'id' => 'my-id', 'class' => 'some more css classes', 'files' => 'true', 'data-url' => 'This could be read in JavaScript']);
        

        methodactionfiles 是 Laravel 特有的,其他值只是属性和值。

        【讨论】:

        【解决方案5】:

        选项列表与不使用php的表单列表相同:

        http://www.w3schools.com/tags/tag_form.asp

        不同的是,属性会以数组格式传递:

        array('action' => 'user.update', 'enctype' => 'multipart/form-data', 'method' => 'PUT')

        如果未指定,默认方法是 POST。

        @编辑

        好像我没说清楚。

        Laravel 只包含一些帮助的属性,如何 url(转换为操作)、路由(转换为操作)、文件(转换为 enctype='multipart/form-data'),但还是一样的。

        文件到enctype的转换:

        if (isset($options['files']) && $options['files'])
        {  
           $options['enctype'] = 'multipart/form-data'; 
        }
        

        【讨论】:

        • 对不起,这个解释太糟糕了,错过了一些重要的点
        猜你喜欢
        • 2013-03-05
        • 2019-02-28
        • 2015-05-16
        • 1970-01-01
        • 2013-07-21
        • 2015-10-19
        • 1970-01-01
        • 2014-06-05
        • 2014-05-11
        相关资源
        最近更新 更多