Php Laravel include原因错误:方法Illumb\View\View::\uu toString()不能引发异常
我在laravel中包含了一个文件,它向我抛出了以下错误:Php Laravel include原因错误:方法Illumb\View\View::\uu toString()不能引发异常,php,laravel,laravel-4,Php,Laravel,Laravel 4,我在laravel中包含了一个文件,它向我抛出了以下错误: Method Illuminate\View\View::__toString() must not throw an exception 我已将该文件包括在内,如下所示: @include('users.opentasks') 我在同一页上使用了两个include,但如果我使用一个,就没有什么区别了 我真的不确定这意味着什么,以及如何解决这一点的新手在这里。希望有人能帮忙 我的代码如下: UserController.php pu
Method Illuminate\View\View::__toString() must not throw an exception
我已将该文件包括在内,如下所示:
@include('users.opentasks')
我在同一页上使用了两个include,但如果我使用一个,就没有什么区别了
我真的不确定这意味着什么,以及如何解决这一点的新手在这里。希望有人能帮忙
我的代码如下:
UserController.php
public function profile() {
$status = "closed";
$data["projects"] = $projects = Auth::user()->projects()->where('status', '!=', $status)
->paginate(4);
//$data["tasks"] = $tasks = Auth::user()->tasks->paginate(4);
// $data["tasks_pages"] = $tasks->links();
//Comments pagination
$data["projects_pages"] = $projects->links();
if(Request::ajax())
{
$html = View::make('users.openprojects', $data)->render();
return Response::json(array('html' => $html));
// $html = View::make('users.opentasks', $data)->render();
// return Response::json(array('html' => $html));
}
echo View::make('users.profile')->with('projects', $projects);
}
public function opentasks() {
$user = User::with(array('tasks', 'tasks.status'))->find(Auth::user()->id);
return View::make('users.opentasks')->with('user', $user);
}
profile.blade.php
@extends("layout")
@section("content")
@include('users.openprojects')
@include('users.opentasks')
@stop
@foreach($user->tasks as $task)
{{ $task->task_name }}
{{ $task->task_brief}}
@if(!is_null($task->status))
{{ $task->status->status_name }}<br/><br/><br/><br/>
@endif
@endforeach
opentasks.blade.php
@extends("layout")
@section("content")
@include('users.openprojects')
@include('users.opentasks')
@stop
@foreach($user->tasks as $task)
{{ $task->task_name }}
{{ $task->task_brief}}
@if(!is_null($task->status))
{{ $task->status->status_name }}<br/><br/><br/><br/>
@endif
@endforeach
@foreach($user->tasks as$task)
{{$task->task_name}
{{$task->task_-brief}
@如果(!为空($task->status))
{{$task->status->status_name}}
@恩迪夫
@endforeach
您可能希望这样做:
if(Request::ajax())
{
// --- this part of the code is odd
$html = View::make('users.openprojects', $data)->render();
return Response::json(array('html' => $html));
// ---
} else {
$user = User::with(array('tasks', 'tasks.status'))->find(Auth::user()->id);
$data = array(
'user' => $user,
'projects' => $projects
);
return View::make('users.profile', $data);
}
echo视图::make('users.profile')->带有('projects',$projects)代码>将echo
更改为return
,这会向我抛出一个未定义变量:user
error,这是因为您@includeopentasks
和openprojects
也需要数据。您还必须将这些数据与返回的视图一起传递。这仍然给了我一个未定义的变量:user errror。将在4分钟内接受。还有,代码的这一部分有什么奇怪之处?我在ajax的在线教程中看到了它call@g_9020我只是不熟悉它。。。但我现在有点明白了。(也许)。它试图返回呈现视图的json响应:D