php - 处理 Laravel Blade View::render() 异常
问题描述
我有一个辅助函数来渲染看起来像这样的动态视图
public function renderDynamicView($path, $data)
{
return View::make($path, $data)->render();
}
现在,如果在提供的视图中发生异常(例如,在提供的视图中缺少信息$data
),代码将只是废话。我如何在这个问题上放置一个通用的 try catch 来为这种情况呈现一个默认视图?我试过类似的东西
public function renderDynamicView($path, $data)
{
try
{
return View::make($path, $data)->render();
}
catch (Exception $e)
{
return View::make('broken')->render();
}
}
以上以某种方式导致Cannot end a section without first starting one.
异常。
解决方案
推荐阅读
- r - 我将如何自动计算各个国家/地区的小标题内的相关性并有效地存储?
- html - 我是否将一段文本的颜色和字体标签放在同一个
- ios - UIScrollView 无法识别 UICollectionView 的内容大小
- python - 如果出错,如何回到python循环的开头?
- regex - 用于交替的正则表达式分组规则
- reactjs - 如何获取 React Native 元素的样式值?
- python - 为什么 json 库不接受我的报价?
- unity3d - 使用上下文 UnityEngine.Object 引发异常
- javascript - 如何在 React Native 的父组件内触发子组件 onPress
- c# - 如何使用自定义线条制作自定义按钮形状