【发布时间】:2015-11-16 09:26:34
【问题描述】:
我正在尝试使用 https://github.com/skmetaly/laravel-twitch-restful-api 包将 twitch 集成到我的网站。
这是我得到的错误。
ErrorException in helpers.php line 469:
htmlentities() expects parameter 1 to be string, array given (View: /var/www/rafdev.ovh/html/msvixen/resources/views/twitch.blade.php)
我的控制器 $code = Input::get('code');
if ($code !== null)
{
$token = TwitchApi::requestToken($code);
} else
{
$token = null;
}
$data = TwitchApi::streamsFollowed($token);
return view('twitch', ['token' => $token, 'data' => $data]);
我的看法
@extends('master')
@section('content')
<h1>Twitch.TV</h1>
{{ $token }}
{{ $data }}
@endsection
使用dd()后
array:9 [▼
0 => array:11 [▼
"_id" => 17733016640
"game" => "World of Warcraft"
"viewers" => 15551
"created_at" => "2015-11-15T22:27:13Z"
"video_height" => 1080
"average_fps" => 60.2769481401
"delay" => 0
"is_playlist" => false
"_links" => array:1 [▶]
"preview" => array:4 [▶]
"channel" => array:22 [▶]
]
1 => array:11 [▶]
2 => array:11 [▶]
3 => array:11 [▶]
4 => array:11 [▶]
5 => array:11 [▶]
6 => array:11 [▶]
7 => array:11 [▶]
8 => array:11 [▶]
]
所以它可以工作,但是当我尝试显示数据时 - 它回到了htmlentities() 错误
【问题讨论】:
-
$token或$data是一个数组而不是一个字符串。使用dd()或类似工具来调试变量。{{ $token }}导致 Blade 在幕后运行htmlentities($token),然后由于上述原因而失败 -
鉴于用于设置
$data的方法名为streamsFollowed(),鉴于它使用复数流,我希望它返回一个数组。 -
我检查了
dd()和$data是一个数组,我尝试用@foreach和$data as $stream显示它,然后使用{{ $stream->streams }}但失败了。你知道如何正确显示这个吗?