2015-06-06 71 views
0
的Symfony2的查詢

請任何人能解釋這些Doctrine指令上Symfony2框架你能給我一些澄清學說

1. $academicYear = $em->getRepository('ComAkSolutionsSmsUserBundle:AcademicYear') 
         ->find($id); 

2. public function manageAcademicClassAction($classId, Request $request) 
    { 

    $em = $this->getDoctrine()->getManager(); 
    $academicClass = $em->getRepository('ComAkSolutionsSmsUserBundle:AcademicClass') 
       ->find($classId); 



    $academicYear = $em->getRepository('ComAkSolutionsSmsUserBundle:AcademicYear') 
       ->find($academicClass->getAcademicYearId()); 


3. $students = $em->getRepository('ComAkSolutionsSmsUserBundle:StudentProfile') 
         ->findBySectionId($sectionId); 

4. $teacherProfile = $em->getRepository('ComAkSolutionsSmsUserBundle:TeacherProfile') 
         ->findOneByUser($user); 
+0

我guessog第一個查詢應該是$ academicClass = ... – Cerad

+0

嗨,我在這樣 – Jecintha

+0

公共職能manageAcademicClassAction這個功能我使用($ CLASSID,請求$請求) { $ EM = $此 - > getDoctrine() - > getManager(); // $ CLASSID是AcademicClassId //獲取AcademicClass $ academicClass = $ EM-> getRepository( 'ComAkSolutionsSmsUserBundle:AcademicClass') - >找到($的classid); $ academicYear = $ em-> getRepository('ComAkSolutionsSmsUserBundle:AcademicYear') - > find($ academicClass-> getAcademicYearId());} – Jecintha

回答

0

find()是在基礎doctrine repository的方法來查找按主鍵的記錄。前兩個例子是相同的,你只是查找不同的存儲庫。

你的第三和第四個例子是custom repositories並且實現了它們自己的方法findBySectionId()和findOneByUser()。

+0

謝謝您發送了這個 – Jecintha

+0

既然您在這裏新建,請不要忘記將我的答案標記爲已接受,如果您認爲它回答了您的問題。乾杯。 –