Laravel 5 列出 htmlentities() 期望参数 1 是字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29059160/
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 5 lists htmlentities() expects parameter 1 to be string
提问by imperium2335
I have the following:
我有以下几点:
\App\Models\Finance\FinanceAccount::lists('name', 'id')
\App\Models\Finance\FinanceAccount::lists('name', 'id')
At the top of one of my views but it keeps giving me the error:
在我的一个观点的顶部,但它不断给我错误:
htmlentities() expects parameter 1 to be string, array given (View: mysite\views\modals\add.blade.php)
What am I doing wrong?
我究竟做错了什么?
That makes sense about it being an array, I put it into a select and it's working now:
这是一个数组,我把它放入一个选择中,现在它正在工作:
<div class="form-group">
{!!Form::label('Account')!!}
{!!Form::select('account', \App\Models\Finance\FinanceAccount::getSelectOptions(), 1, ['class' => 'form-control'])!!}
</div>
Is there a way to set the namespace for views, so I don't have to type the full namespace all the time?
有没有办法为视图设置命名空间,这样我就不必一直输入完整的命名空间?
回答by Marwelln
lists
gives an array and that's not something you can echo out with {{ }}
. What you need to do is to loop or implode
the array if you want to print it's content.
lists
给出一个数组,这不是你可以用{{ }}
. implode
如果你想打印它的内容,你需要做的是循环或数组。
With foreach
和 foreach
@foreach ($list as $item)
{{ $item }}<br />
@endforeach
With implode
和 implode
{{ implode(', ', $list) }}
With Form::select
和 Form::select
{!! Form::select('foo', $list) !!}
If you don't want to use your namespace (which you never should) in your view, send the datafrom your controller to your view file.
如果您不想在您的视图中使用您的命名空间(您永远不应该使用),请将数据从您的控制器发送到您的视图文件。
If you have this in your controller
如果你的控制器中有这个
public function foo() {
$baz = \App\Models\Finance\FinanceAccount::getSelectOptions();
return view('bar', compact('baz'));
}
The $baz
variable is then available in your view file. So you can do this:
$baz
然后该变量在您的视图文件中可用。所以你可以这样做:
{!! Form::select('foo', $baz) !!}