은이 코드를 사용하여 객체를 편집하고 있습니다 :변수에 값이 있지만 양식 표시가 비어 있습니다. 이유는 무엇입니까?
이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
이 값으로 오는 것을 알 수 있습니다 : 다른 측면에서
나는 내가에 디버그를 동일하지만, 나뭇 가지 템플릿에서 할 않았다
지금은 혼란 스러워요 내가 희망, 두 가지 아이디어와 함께이 시점에서, 누군가가 나 개발하거나 적어도 이해하는 데 도움이 다음form
VAR 나는이 얻을.
entity
에서 모든 정보를 사용하여 해결책을 찾고 올바른 양식을 표시합니다.보기로 전달합니다. 이것은 이상적이며 배우기 위해이 작업을하고 싶습니다. 그래서 도움이 될까요?- 컨트롤러에
Person
개체를 가져오고Person
개체 값을 전달하여 두 번째 양식을 만드십시오. 양식이 별도로 이동하므로update
함수에서 많은 변경이 필요합니다.
은 내가 여기에서 필요로하는 것은 얻을 수있는 NaturalPersonType
또는 OrdersType
에 지금 내가 나뭇 가지 템플릿의 위젯을 표시하는 방법을 모르기 때문에 내가 존재 Orders
을 편집하려면 시간을 포함 LegalPersonType
.
이
NaturalPersonType 추가 OrdersType FormTypeclass 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'; } }
그것은 당신이 요구하는지 분명하지 않다.얻으려는 결과를 정확하게 설명해 주시겠습니까? 또한,'Type'의 코드를 보는 것이 유용 할 것입니다. – FyodorX
@FyodorX 좀 더 자세한 정보를 추가하고 다른 것을 필요로하면 – ReynierPM