响应内容必须是实现__toString(), \“布尔值”给定的字符串或对象。
我正在尝试返回渲染的视图,但我收到此错误:Response::json
The Response content must be a string or object implementing __toString(), \"boolean\" given."
这是我的代码:
$posts = Post::where( ... )->orderBy( ... )->get();
$data['posts'] = View::make("posts.partials.loadHome")->with("posts", $posts)->render();
$data['msg'] = "ok";
return Response::json($data);
如果我得到这个:var_dump($data)
<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=2)</i>
'posts' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'<div class="post postGrid" data-id="1864"> <a target='_blank' href="http://objavi.net/posts/1864"><img src="http://objavi.net/" id="imgWrap" data-original="/thumbs/YAo4wFzIpl76.jpg" class="lazy" alt="Deset manje poznatih činjenica o Jozefu Staljinu"></a> <div id="bodyPreview"> <a target='_blank' href="http://objavi.net/posts/1864"><h1 class="previewTitle">Deset manje poznatih činjenica o Jozefu Staljinu</h1></a> <h3 id="postInfo"> <a class="paint" href="/category/17">zanimljivosti</a> '...</font> <i>(length=12172)</i>
'msg' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'ok'</font> <i>(length=2)</i>
</pre>
这是视图:posts.partials.loadHome
@foreach($posts as $post)
<div class="post postGrid" data-id="{{ $post->id }}">
<a target='_blank' href="{{ URL::action('PostsController@show', $post->id) }}">{{ HTML::image(null, $post->title, ["id" => "imgWrap", "data-original" => $post->getThumb(), "class" => "lazy"]) }}</a>
<div id="bodyPreview">
<a target='_blank' href="{{ URL::action('PostsController@show', $post->id) }}"><h1 class="previewTitle">{{ e($post->title) }}</h1></a>
<h3 id="postInfo">
@foreach($post->categories as $c)
<a class="paint" href="/category/{{ $c->id }}">{{ $c->name }}</a>
@endforeach
</h3>
<h2 class="bodyPreview">{{ strip_tags(truncString($post->body, 160)) }}</h2>
<div id="createdBy">
<a href="{{ URL::action('UsersController@show', $post->user()->first()->id) }}">
{{ HTML::image($post->user()->first()->getAvatar(), $post->user()->first()->username, ["width" => "32", "height" => "32"]) }}
{{{ $post->user()->first()->username }}}
</a>
<label id="timeAgo">{{ localDate($post->created_at); }}</label>
</div>
</div>
</div>
@endforeach
我在本地主机上测试了这个,一切都很好。可能是什么问题?