我有下一个代码
$html = '';
foreach ($posts as $post) {
$html .= '<div class="table-scrollable">
<table id="posts" class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Title</th>
</tr>
</thead>
<tbody id="body"><tr>
<td>'
. $post->id . '
</td>
<td>' .
$post->name .
'</td>
<td>'
. $post->title .
'</td>
</tr>
</tbody>
</table>
</div>';
}
return PDF::load($html, 'A4', 'portrait')->download('my_pdf');问题是,当我想下载这么多数据时,我将得到下一个错误The localhost page isn’t working localhost is currently unable to handle this request.,但是如果我尝试下载例如20个条目,工作正常。我能做什么?
laravel.log
2016-11-24 13:15:17 production.ERROR: production.ERROR堆栈跟踪中带有消息“未定义变量:data_start”的异常“ErrorException”: 0 /Applications/XAMPP/xamppfiles/htdocs/dicom/app/controllers/IncasariController.php(58): 照明\Exception\Handler->handleError(8,“未定义的varia.”,‘/Applications/X.’,58,Array) 1内部功能: IncasariController->filtrareChitante() 2个/Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): Call_user_func_array(阵列,阵列) 3个/Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('filtrareChitant...',阵列) 4 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(IncasariController),对象(照亮\路由\路由)、‘filtrareChitant.’) 5 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/Router.php(962): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route),对象(照明\Http\请求)、‘IncasariControl.’、‘filtrareChitant.’) 6内部功能: Illuminate\Routing\Router->Illuminate\Routing{closure}() 7 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): Call_user_func_array(对象(闭包),数组) 8个/Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1028): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) 9 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) 10 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) 11 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request)) 12 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request),1,真) 13 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request),1,真) 14 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request),1,真) 15 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request),1,真) 16 /Applications/XAMPP/xamppfiles/htdocs/dicom/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request)) 17 /Applications/XAMPP/xamppfiles/htdocs/dicom/public/index.php(49):照明\Foundation\Application->run() 18 {main}
在网页上有:
The localhost page isn’t working
localhost is currently unable to handle this request.发布于 2016-11-23 14:08:46
您的代码假设每个记录都有一个ID、名称和标题。
在调用它们之前,我会检查它们是否真的设置好了。
就像这样。
foreach ($posts as $post) {
$id= isset($post->id) ? $post->id : 'ID Not Set';
$name= isset($post->name) ? $post->name : 'Name Not Set';
$title= isset($post->title) ? $post->title : ' Title Not Set';
$html .= '<div class="table-scrollable">
<table id="posts" class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Title</th>
</tr>
</thead>
<tbody id="body">
<tr>
<td>'. $id .'</td>
<td>'. $name .'</td>
<td>'. $title .'</td>
</tr>
</tbody>
</table>
</div>';
}如果没有设置它们,则可能导致代码失败,而对象没有找到错误。
您可以从“存储/日志”文件夹检查日志。
发布于 2021-04-09 11:11:42
您可以尝试将大型数据集导出到PDF中。我的建议是:
https://stackoverflow.com/questions/40758428
复制相似问题