2014-09-14 2 views
0

은이 코드를 사용하여 객체를 편집하고 있습니다 :변수에 값이 있지만 양식 표시가 비어 있습니다. 이유는 무엇입니까?

public function editAction($id = null) 
{ 
    $em = $this->getDoctrine()->getManager(); 
    $order = $em->getRepository('FrontendBundle:Orders')->find($id); 
    $type = $order->getPerson()->getPersonType() === 1 ? "natural" : "legal"; 

    ladybug_dump_die($order); 

    $orderForm = $this->createForm(new OrdersType(array($type)), $order, array(
     'action' => $this->generateUrl('update-order', array('id' => $id)), 
     'method' => 'POST', 
     )); 

    return array(
     'entity' => $order, 
     "form" => $orderForm->createView(), 
     'id' => $id 
    ); 
} 

내가 알고 아니에요 것을 제외하고는 잘가 작동하는 모든/객체 Person 값을 표시하는 방법을 찾을 수 있습니다. 당신은 내가 여기에 첨부 한 사진을 살펴 경우에 당신은 Person이 값으로 오는 것을 알 수 있습니다 : 다른 측면에서

Controller Debug

나는 내가에 디버그를 동일하지만, 나뭇 가지 템플릿에서 할 않았다

Twig Render

지금은 혼란 스러워요 내가 희망, 두 가지 아이디어와 함께이 시점에서, 누군가가 나 개발하거나 적어도 이해하는 데 도움이 다음 form VAR 나는이 얻을.

  1. entity에서 모든 정보를 사용하여 해결책을 찾고 올바른 양식을 표시합니다.보기로 전달합니다. 이것은 이상적이며 배우기 위해이 작업을하고 싶습니다. 그래서 도움이 될까요?
  2. 컨트롤러에 Person 개체를 가져오고 Person 개체 값을 전달하여 두 번째 양식을 만드십시오. 양식이 별도로 이동하므로 update 함수에서 많은 변경이 필요합니다.

은 내가 여기에서 필요로하는 것은 얻을 수있는 NaturalPersonType 또는 OrdersType에 지금 내가 나뭇 가지 템플릿의 위젯을 표시하는 방법을 모르기 때문에 내가 존재 Orders을 편집하려면 시간을 포함 LegalPersonType.

enter image description here

NaturalPersonType 추가 OrdersType FormType

class OrdersType extends AbstractType { 

    /** 
    * @var string 
    */ 
    protected $register_type; 

    public function __construct($register_type) 
    { 
     $this->register_type = $register_type; 
    } 

    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder 
       ->add('nickname', 'text', array(
        'required' => FALSE, 
        'label' => "Nickname/Seudónimo", 
        'trim' => TRUE, 
        'attr' => array(
         'class' => 'nickname' 
        ) 
       )) 
       ->add('email', 'email', array(
        'required' => TRUE, 
        'label' => "Correo Electrónico", 
        'trim' => TRUE 
       )) 
       ->add('phone', 'tel', array(
        'required' => TRUE, 
        'label' => 'Números de teléfono (separados por "/")', 
        'trim' => TRUE, 
        'default_region' => 'VE', 
        'format' => PhoneNumberFormat::NATIONAL 
       )) 
       ->add('fiscal_address', 'textarea', array(
        'required' => TRUE, 
        'label' => 'Dirección' 
       )) 
       ->add('shipping_address', 'textarea', array(
        'required' => TRUE, 
        'label' => 'Dirección de Envío' 
       )) 
       ->add('shipping_from', 'choice', array(
        'label' => 'Compañía de Encomiendas', 
        'choices' => SFType::getChoices(), 
        'empty_value' => '-- SELECCIONAR --' 
       )) 
       ->add('payment_type', 'entity', array(
        'class' => 'CommonBundle:PaymentType', 
        'property' => 'name', 
        'required' => TRUE, 
        'label' => 'Forma de Pago', 
        'empty_value' => '-- SELECCIONAR --' 
       )) 
       ->add('order_amount', 'number', array(
        'label' => 'Monto', 
        'required' => TRUE, 
        'precision' => 2 
       )) 
       ->add('bank', 'entity', array(
        'class' => 'CommonBundle:Bank', 
        'property' => 'name', 
        'required' => TRUE, 
        'label' => 'Banco', 
        'empty_value' => '-- SELECCIONAR --' 
       )) 
       ->add('transaction', 'text', array(
        'required' => TRUE, 
        'label' => 'No. Transacción' 
       )) 
       ->add('comments', 'textarea', array(
        'required' => FALSE, 
        'label' => 'Comentarios' 
       )) 
       ->add('secure', 'checkbox', array(
        'label' => FALSE, 
        'required' => FALSE, 
        'value' => 1, 
        'mapped' => FALSE 
       )) 
       ->add('lives_in_ccs', 'checkbox', array(
        'label' => false, 
        'required' => false, 
        'mapped' => FALSE, 
        'value' => 1, 
       )) 
       ->add('suscribe_mail_list', 'checkbox', array(
        'label' => FALSE, 
        'required' => FALSE, 
        'value' => 1, 
        'mapped' => FALSE 
     )); 

     if ($this->register_type[0] == "natural") 
     { 
      $builder->add('nat', new NaturalPersonType(), array('mapped' => FALSE)); 
     } 
     elseif ($this->register_type[0] == "legal") 
     { 
      $builder->add('leg', new LegalPersonType(), array('mapped' => FALSE)); 
     } 
    } 

    public function setDefaultOptions(OptionsResolverInterface $resolver) 
    { 
     $resolver->setDefaults(array(
      'data_class' => 'Tanane\FrontendBundle\Entity\Orders', 
      'render_fieldset' => FALSE, 
      'show_legend' => FALSE, 
      'intention' => 'orders_form' 
     )); 
    } 

    public function getName() 
    { 
     return 'orders'; 
    } 

} 

추가 : 결국 내가이 경우에 대해 이야기하고있는 형태의 공지 사항은 NaturalPersonType 렌더링하지만없는 값이다

<?php namespace Tanane\FrontendBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Tanane\FrontendBundle\DBAL\Types\CIType; class NaturalPersonType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder ->add('identification_type', 'choice', array( 'label' => 'Número de Cédula', 'choices' => CIType::getChoices() )) ->add('ci', 'number', array( 'required' => true, 'label' => false, 'attr' => array( 'maxlength' => 8, )) ) ->add('person', new PersonType(), array('mapped' => FALSE)); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Tanane\FrontendBundle\Entity\NaturalPerson' )); } public function getName() { return 'natural_person'; } } 
+0

그것은 당신이 요구하는지 분명하지 않다.얻으려는 결과를 정확하게 설명해 주시겠습니까? 또한,'Type'의 코드를 보는 것이 유용 할 것입니다. – FyodorX

+0

@FyodorX 좀 더 자세한 정보를 추가하고 다른 것을 필요로하면 – ReynierPM

답변

1

T 그는 문제가 귀하의 Type에 있습니다. 보시다시피 옵션은 natleg 모두에 대해 false으로 설정됩니다. 즉, Symfony은 해당 필드를 엔티티와 연결하지 않으므로보기를 렌더링 할 때 비어 있습니다.

난 당신이 모델의 이러한 속성 중 하나를 가지고 있지 않기 때문에 당신이 그런 식으로했던 것 같아요,하지만 당신은이 person을 할 . 당신이해야 할 일은 NaturalPersonType 또는 LegalPersonTypeperson에 매핑하는 것입니다.

가장 쉬운 방법은 귀하의 경우이로 OrdersTypebuildForm()의 마지막 라인을 교체하는 것이라고 할 수 있습니다 :

if ($this->register_type[0] == "natural") 
    { 
     $builder->add('person', new NaturalPersonType(), array('label' => FALSE)); 
    } 
    elseif ($this->register_type[0] == "legal") 
    { 
     $builder->add('person', new LegalPersonType(), array('label' => FALSE)); 
    } 
+0

이 경우 다음과 같은 오류가 발생합니다. '속성 "또는"getNat() ","getNat 클래스 "Tanane \ FrontendBundle \ Entity \ Orders"에 public 액세스 권한이 있습니다. ","isNat() ","isNat() ","hasNat() ","__get 내 엔티티 매핑에 대한 전체보기를 얻으려면 [this post] (http://stackoverflow.com/questions/25713074/onetomany-or-onetoone-im-in-the-right-or-wrong-path)를 참조하십시오. Doctrine ** 클래스 테이블 상속 **을 사용하고 있습니다. 어떻게 작동합니까? – ReynierPM

+0

두 필드 모두 '사람'이라고 확신합니까? 'nat'은 더 이상 존재하지 않아야합니다. – FyodorX

+0

이 경우는 yes입니다. Fixtures에서로드 된 테스트 데이터이고 yes는 모두 NaturalPersonType입니다. 문제를 해결하려면 어떻게해야합니까? – ReynierPM

관련 문제