、その後、SensioFrameworkExtraBundle ParamConverterは自動的にエンティティ(データベースレコード)を取得することができます。
独自にメソッドのシグネチャを用いることで、より簡単かつ迅速な方法があるので、一般的である
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
/**
* @Route("/blog/{id}")
* @ParamConverter("post", class="SensioBlogBundle:Post")
*/
public function showAction(Post $post)
{
}
:「PRODの環境(ライブサーバー)で
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Route("/blog/{id}")
*/
public function showAction(Post $post)
{
// $post will be the database record - if it exists
}
、もしそこにあなたが/blog/1
にアクセスしたとき、id:1(例えば) 'post'テーブルにレコードがないと、フレームワークは404エラーを生成します。
自分自身(またはそのより複雑な)で検索をしたい場合は、「NotFoundHttpException」を作る、またはそうするように、コントローラのショートカットを使用することができます。
public function indexAction(/* parameters, like Request, or maybe $id */)
{
// retrieve the object from database
$product = ...;
if (!$product) {
throw $this->createNotFoundException('The product does not exist');
}
return $this->render(...);
}