我想将2个数组传递给控制器中的render
函数。
我该怎么做?
现在我有类似的东西:
class GradebookController extends Controller
{
/**
* @Route("/gradebook", name="_gradebook")
*/
public function indexAction()
{
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
return $this->redirect($this->generateUrl('_login'));
}
$em = $this->getDoctrine()->getManager();
$subject = $em->getRepository('AppBundle:Subject')->findAll();
$students = $em->getRepository('AppBundle:User')->findBy(
array('roles'=>'a:0:{}')
);
return $this->render('::gradebook.html.twig', array('students'=>$students),
array('subjects'=>$subject));
}
}
答案 0 :(得分:2)
将两者合并为一个包含多个键的数组。
return $this->render('::gradebook.html.twig', array('students' => $students, 'subjects' => $subject));