私は Symfony と Doctrine の初心者です。「カテゴリ」からすべての「質問」を返す関数を構築しようとしています。私は動作するこのコードを書きましたが、SF ツールバーはそれが正しい方法ではないことを教えてくれます。
これが私のコードです:
public function showAction(Category $category)
{
$c_id = $category->getId();
$em = $this->getDoctrine()->getEntityManager();
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT id, title FROM question WHERE category_id = $c_id");
$statement->execute();
$questions = $statement->fetchAll();
return $this->render('IelCategoryBundle:Category:show.html.twig', array(
'category' => $category,
'questions' => $questions
));
}
これを書くためのより良い方法があると確信していますが、私はこの教義コードに慣れていません. アドバイスをいただければ幸いです。:-)