심포니 2.1 베타 4 내가 form_widget를 사용하려고하거나 form_rest, 나는이 오류가 발생합니다 만약 내가, 내 나뭇 가지 템플릿에 내 양식을 렌더링하고Symfony2 정의되지 않은 인덱스 부모 양식
렌더링 할 때 - "예외를 템플릿 ("알림 : 정의되지 않은 색인 : MySite/vendor/symfony/symfony/src/Symfony/Component/Form/FormView.php 줄 308의 부모) 렌더링 중 throw됩니다." form_row를 사용하여 수동으로 양식을 작성하고 특성을 갱신 할 수 있지만 csrf 토큰은 포함하지 않습니다.
편집 7/27 PropertyType 양식 클래스 만 포함하면 form_rest가 정상적으로 작동하는 것처럼 보입니다. AddressType을 포함 시키면 위의 오류가 발생합니다.
주소 엔티티가 내장 된 속성 (즉, 집) 엔티티를 렌더링 중입니다.
public function showAction($property_id)
{
$em = $this->getDoctrine()->getEntityManager();
$property = $em->getRepository('MySystemBundle:Property')->find($property_id);
if(!$property){
throw $this->createNotFoundException('The requested property does not exist.');
}
$form = $this->createForm(new PropertyType(), $property);
$request = $this->get('request');
if($request->getMethod() == 'POST'){
$form->bind($request);
if($form->isValid()){
$em->persist($property);
$em->flush();
$this->get('session')->setFlash('notice', 'Your changes were saved!');
return $this->redirect($this->generateUrl('system_propertyShow',
array('property_id' => $property_id)));
}
}
$vars['property'] = $property;
$vars['form'] = $form->createView();
return $this->render('MySystemBundle:Property:show.html.twig', $vars);
}
내 PropertyType 양식 클래스 :
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class PropertyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('purchaseAmount', 'text', array('label' => 'Purchase Amount', 'required' => false))
->add('depositAmount', 'text', array('label' => 'Deposit Amount', 'required' => false))
->add('additionalCostsAmount', 'text', array('label' => 'Additional Costs', 'required' => false))
->add('balanceAmount', 'text', array('label' => 'Balance', 'required' => false))
->add('dateBalanceDue', 'datetime', array('label' => 'Balance Due', 'widget' => 'single_text', 'required' => false))
->add('squareFootage', 'number', array('label' => 'Square Footage', 'required' => false))
->add('isOccupied', 'choice', array(
'label' => 'Is Occupied?',
'choices' => array('1' => 'Yes', '0' => 'No'),
'required' => false))
->add('address', new AddressType());
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'MySite\Bundle\SystemBundle\Entity\Property');
}
public function getName()
{
return 'property';
}
}
편집 7/27 : 당신을위한
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class AddressType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('line1', 'text', array('label' => 'Line 1'))
->add('line2', 'text', array('label' => 'Line 2', 'required' => false))
->add('line3', 'text', array('label' => 'Line 3', 'required' => false))
->add('city', 'text', array('label' => 'City'))
->add('township', 'text', array('label' => 'Township', 'required' => false))
->add('zipcode', 'text', array('label' => 'Zip'))
->add('state', new StateType());
}
public function getDefaultOptions(array $options)
{
return array('data_class' => 'MySite\Bundle\SystemBundle\Entity\Address');
}
public function getName()
{
return 'address';
}
}
PropertyType 클래스를 볼 수 있습니까? form_widget이나 form_rest가 예외를 던지면 처음부터 제대로 작동하지 않는다고 생각합니다. 양식이 제대로 작성된 경우이를 사용할 수 있어야합니다. – mask8
좋아, 작게 시작하고 싶기 때문에이 시점에서 모든 항목을 구현하지 않았습니다. – mhoff
'AddressType'이라는 사용자 정의 양식 필드가 있는데, 클래스에서'getParent()'함수를 올바르게 구현 했습니까? 사용자 정의 필드에 대한 나뭇 가지 위젯 템플릿을 만들었습니까? 또한'FormBuilderInterface'는'FormBuilder' 여야한다고 생각합니다. – mask8