Symfonyノート--コントローラのショートカット方法
Shortcuts methods in Controller
1.サービスの取得
2.リダイレクト
3.ルーティングのurlを生成する
4.json responseを返す
5.flash messageを追加
6.ある方法へのアクセスを許可するかどうかを判断する
7.ユーザーが許可したかどうかを判断し、いいえ、例外を投げ出す
8.CSRF tokenが合法かどうかを手動で判断する
9.要求を他のコントローラと方法に転送する
10.ファイルダウンロード(symfony>=3.2)
11.構成パラメータの読み込み
1.サービスの取得
$this->get($serviceId);
2.リダイレクト
$this->redirectToRoute($routeName, $parameters, $status = 302);
3.ルーティングのurlを生成する
$this->generateUrl($routeName, $parameters, $referenceType);
4.json responseを返す
$this->json($data, $status = 200, $headers = array(), $context = array());
5.flash messageを追加
$this->addFlash($type, $message);
6.ある方法へのアクセスを許可するかどうかを判断する
$this->isGranted('ROLE_ADMIN');
7.ユーザーが許可したかどうかを判断し、いいえ、例外を投げ出す
$this->denyAccessUnlessGranted('ROLE_EDIT', $item, 'You cannot edit this item.');
8.CSRF tokenが合法かどうかを手動で判断する
$this->isCsrfTokenValid('token_id', $token);
9.要求を他のコントローラと方法に転送する
$this->forward('GregwarCaptchaBundle:Captcha:generateCaptcha', ['key' => $key]);
//forward($controller, array $path = array(), array $query = array())
PS: route ,
10.ファイルダウンロード(symfony>=3.2)
$this->file();
//
return $this->file($docPath, $saveName);
// pdf , , ResponseHeaderBag::DISPOSITION_INLINE
// File UploadedFile
//$samplePdf = new File('/sample.pdf');
//return $this->file($samplePdf);
11.構成パラメータの読み込み
$this->getParameter('kernel.root_dir');