你能否给我一些关于Symfony2教义查询的澄清

时间:2015-06-06 11:22:09

标签: symfony

任何人都可以解释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);

1 个答案:

答案 0 :(得分:0)

find()是基本doctrine repository中按主键查找记录的方法。前两个示例是相同的,您只是查找不同的存储库。

您的第3和第4个示例是custom repositories并实现了自己的方法findBySectionId()和findOneByUser()。