throw new AccessDeniedHttpException();
因此,它使用twig返回我的自定义403错误html模板。
<div class="jumbotron jumbotron-fluid exception">
<table class="wrapper">
<tr>
<td>
<div class="error-code">
<span>403</span>
<div class="caption">
<h1 class="text-light">Test h1</h1>
<h2 class="text-light">Test h2</h2>
<p>
Test
</p>
</div>
</div>
</td>
</tr>
</table>
</div>
现在我想做的是,同样的:
抛出新的AccessDeniedHttpException();
根据发生错误的情况使用不同的消息403。
例如,我试图做的是:
throw new AccessDeniedHttpException('custom');
在我的模板403.html.twig中
<div class="jumbotron jumbotron-fluid exception">
<table class="wrapper">
<tr>
<td>
{% if status_text %}
{{ status_text }}
{% else %}
<div class="error-code">
<span>403</span>
<div class="caption">
<h1 class="text-light">Test h1</h1>
<h2 class="text-light">Test h2</h2>
<p>
Test
</p>
</div>
</div>
{% endif %}
</td>
</tr>
</table>
但我不知道在我的错误模板中是否可以访问异常中传递的字符串。。。