2017-03-19 8 views
0

が参加し、代わりにそのテーブルのIDsymfonyでカスタムクエリを作成するには?私は、内部でカスタムクエリを作成する必要が

public function showAction($id) 
{ 
    $em = $this->getDoctrine()->getManager(); 

    $entity = $em->getRepository('chriscrudBundle:BpCrpCard')->find($id); 

    if (!$entity) { 
     throw $this->createNotFoundException('Unable to find BpCrpCard entity.'); 
    } 

    $deleteForm = $this->createDeleteForm($id); 

    return $this->render('chriscrudBundle:BpCrpCard:show.html.twig', array(
     'entity'  => $entity, 
     'delete_form' => $deleteForm->createView(), 
    )); 
} 

答えて

0
$qb->select('bp.name') 
->innerJoin('bp.phones', 'p', 'WITH', 'p.id' =   'bp.id'); 
+0

説明なしのコードのみの回答は良くありません。 – Blackbam

+0

これは質問に対する答えを提供しません。十分な[評判](http://stackoverflow.com/help/whats-reputation)があれば、[任意の投稿にコメントする]ことができます(http://stackoverflow.com/help/privileges/comment)。代わりに、[質問者からの説明を必要としない回答を提供する](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- i-do-代わりに)。 - [レビューの投稿](レビュー/低品質の投稿/ 15572781) – Blackbam

+0

ありがとうございました –

0

の名前を表示するあなたのリポジトリにDQLのおかげで、いくつかのカスタムクエリを作成することができます
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html

$em = $this->getDoctrine()->getManager(); 
$connection = $em->getConnection(); 
$statement = $connection->prepare("SELECT foo WHERE bar = :id"); 
$statement->bindValue('id', 1); 
$statement->execute(); 
$results = $statement->fetchAll(); 

DoctrineのCRE:

また、生のSQLをこの方法で行うことができますあなたのリポジトリにいくつかの魔法ゲッターもあります:findByColumneName(param)またはfindOneByColumnName(param)

関連する問題