laravel htmlentities() 期望参数 1 是字符串,给定数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21732931/
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
htmlentities() expects parameter 1 to be string, array given
提问by babbaggeii
I'm trying to add a class to a laravel form. The array is being passed as the third argument, as required, but I get the above error.
我正在尝试向 Laravel 表单添加一个类。根据需要,该数组作为第三个参数传递,但出现上述错误。
{{ Form::input('text', $variable->name, array('class' => 'form-control')) }}
If I get rid of the third argument, the form displays as expected (unstyled). I can't see what I'm doing wrong here - can anyone help?
如果我去掉第三个参数,表单会按预期显示(无样式)。我看不出我在这里做错了什么 - 任何人都可以帮忙吗?
回答by JohnTaa
{{ Form::text('text', $variable->name, array('class' => 'form-control')) }}
回答by babbaggeii
I can see from the api that there is another argument expected:
我可以从 api 中看到还有另一个参数:
http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246
http://laravel.com/api/source-class-Illuminate.Html.FormBuilder.html#235-246
('text', $name, $value, $options)
回答by alexrussell
Your array needs to be the fourth argument to Form::input()
- the third is the 'default' value. See Laravel's FormBuilder
class:
您的数组需要是第四个参数Form::input()
- 第三个是“默认”值。参见 Laravel 的FormBuilder
类:
public function input($type, $name, $value = null, $options = array())