템플릿 엔진으로 Symfony2와 나뭇 가지를 사용합니다. 내 컨트롤러에서템플릿에 선택 필드를 렌더링하는 방법
나는 다음과 같은 형식이 있습니다
$usr= $this->get('security.context')->getToken()->getUser();
$associatedmissions = array($usr->getMissions());
$form = $this->createFormBuilder($product)
->add('mission', 'choice', array(
'choices' => $associatedmission,
'multiple' => false,
'expanded' => true,))
을하지만 페이지를 호출 할 때 오류가 나타납니다 :
: 나는 오류를 볼 수 있습니다Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be
converted to string in
C:\BitNami\wampstack-5.4.23-
0\frameworks\symfony\vendor\symfony\symfony\src\Symfony\Component\Translation\
IdentityTranslator.php line 65
프로파일에서을
CRITICAL - Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown
during the rendering of a template ("") in "form_div_layout.html.twig" at line 99." at
C:\BitNami\wampstack-5.4.23-0\frameworks\symfony\app\cache\dev\classes.php line 4372
Context: {"exception":"Object(Twig_Error_Runtime)"}
무슨 일이 일어 났습니까? 리디렉션을 사용하는
public function createAction(Request $request)
{
$product = new Product();
$usr= $this->get('security.context')->getToken()->getUser();
$associatedmissions = array($usr->getMissions());
$form = $this->createFormBuilder($product)
->add('name', 'text')
->add('mission', 'choice', array(
'choices' => $associatedmissions,
'multiple' => false,
'expanded' => false,))
->add('save', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
return $this->render('AcmeGroundStationBundle:Product:tasksuccess.html.twig', array('product' => $product));
}
return $this->render('AcmeGroundStationBundle:Product:formupload.html.twig', array(
'form' => $form->createView()
));
}
그리고'twig'에서 필드를 어떻게 렌더링하고 있습니까? –
@Victor 이제'{{form_start (form)}} {{form_end (form)}}' –
그냥'$ form-> createView()'와 같은'form' 변수를'return'에 나뭇 가지로 전달합니까 $ this -> render()'method? –