Custom Exception
ExceptionController
namespace KitBaseBundleController; use SymfonyBundleTwigBundleControllerExceptionController as BaseController; use SymfonyComponentHttpFoundationRequest; use KitAdminBundleServiceThemeService; class ExceptionController extends BaseController { private $theme; public function __construct(Twig_Environment $twig, $debug,ThemeService $theme) { parent::__construct($twig, $debug); $this->theme = $theme; } /** * @param Request $request * @param string $format * @param int $code An HTTP response status code * @param bool $showException * * @return string */ protected function findTemplate(Request $request, $format, $code, $showException) { $themeName = $this->theme->get(); $name = $showException ? "exception" : "error"; if ($showException && "html" == $format) { $name = "exception_full"; } // For themes error pages if (!$showException) { $template = sprintf("@KitWeb/theme/".$themeName."/Exception/%s%s.%s.twig", $name, $code, $format); if ($this->templateExists($template)) { return $template; } } // try to find a template for the given format $template = sprintf("@KitWeb/theme/".$themeName."/Exception/%s.%s.twig", $name, $format); if ($this->templateExists($template)) { return $template; } return parent::findTemplate($request, $format, $code, $showException); } }
ThemeService.php
doctrine = $doctrine; } public function get($default = "Default") { /** * * @var KitAdminBundleRepositoryThemeRepository $repo */ $repo = $this->doctrine->getRepository("KitAdminBundle:Theme"); $theme = $repo->findOneBy([ "status" => 1 ]); return (!empty($theme) && !empty($theme->getPath())) ? $theme->getPath() : $default; } }
config.yml
# Twig Configuration twig: .... exception_controller: twig.controller.exception:showAction
service.yml
kit_admin.theme_service: class: KitAdminBundleServiceThemeService arguments: ["@doctrine"] twig.controller.exception: class: KitBaseBundleControllerExceptionController arguments: ["@twig","%kernel.debug%", "@kit_admin.theme_service"]
views
# KitWebBundle/Resources/views/theme/Luxe/Exception/error.html.twig{{ theme_name }} self excption error
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/28123.html
摘要:獲取服務(wù)重定向生成路由的返回一個(gè)添加一個(gè)判斷是否授權(quán)進(jìn)入某個(gè)方法判斷用戶是否授權(quán),否,拋出異常手動(dòng)判斷是否合法把請(qǐng)求轉(zhuǎn)發(fā)到其他控制器和方法第二個(gè)參數(shù)為上占位符參數(shù),第三個(gè)為其他額外的參數(shù)文件下載簡單用法示例如果是之類, Shortcuts methods in Controller 1. 獲取服務(wù) $this->get($serviceId); 2. 重定向 ...
摘要:獲取登錄用戶信息控制器中等價(jià)于中游客用戶密碼加密校驗(yàn)密碼密碼加密文件上傳相關(guān)獲取上傳的文件不為空未上傳獲取根目錄和獲取當(dāng)前路由名稱 Symfony Basic 獲取登錄用戶信息 控制器中 $this->getUser(); //等價(jià)于 $this->get(security.token_storage) ->getToken() ->g...
摘要:框架關(guān)鍵技術(shù)解析讀書筆記二第五章框架應(yīng)用程序根目錄版本默認(rèn)的框架應(yīng)用程序是符合規(guī)范的,所以相應(yīng)的目錄結(jié)構(gòu)也是基本固定的,不同的目錄加載了功能文件,如果添加了新的目錄,需要在文件中添加規(guī)范的自動(dòng)加載部分并執(zhí)行命令。 Laravel 框架關(guān)鍵技術(shù)解析·讀書筆記(二) 第五章 框架應(yīng)用程序根目錄(5.1版本) 默認(rèn)的Laravel框架應(yīng)用程序是符合PSR規(guī)范的,所以相應(yīng)的目錄結(jié)構(gòu)也是基本...
摘要:可以使用來做,也是作者開發(fā)的,可靠性也有保證。不管怎樣,總會(huì)遇到很多不僅僅一個(gè)需要的,這個(gè)具有公用性的就可以做成一個(gè)放在公司內(nèi)部搭建的鏡像上,這也極大提高整體的開發(fā)效率。 隨著業(yè)務(wù)越來越復(fù)雜,有些service具有通用性,即Repo A中的某一service其他的幾個(gè)Repo都會(huì)不同程度的需要,如果能把該service作為一個(gè)獨(dú)立的package,這樣其他的Repo可以composer...
摘要:異常即使程序的語法是正確的,但是在運(yùn)行的時(shí)候,也有可能發(fā)生錯(cuò)誤,運(yùn)行期監(jiān)測到的錯(cuò)誤稱為異常。此時(shí)可以打印出錯(cuò)誤信息,然后再次把異常拋出。這個(gè)子句將在子句沒有發(fā)生任何異常的時(shí)候執(zhí)行。異常類繼承自,可以直接繼承,或者間接繼承。 1. 語法錯(cuò)誤 Python 的語法錯(cuò)誤被稱為解析錯(cuò),語法分析器會(huì)指出出錯(cuò)的代碼行,并且在最先找到的錯(cuò)誤的位置標(biāo)記一個(gè)小小的箭頭。 >>> while True ...
閱讀 2868·2021-11-22 14:44
閱讀 613·2021-11-22 12:00
閱讀 3756·2019-08-30 15:54
閱讀 1646·2019-08-29 17:15
閱讀 1973·2019-08-29 13:50
閱讀 1182·2019-08-29 13:17
閱讀 3575·2019-08-29 13:05
閱讀 1236·2019-08-29 11:31