0
我想表明從數據庫中的實體領域的數據,但數據未顯示在實體領域,當我打開編輯的形式,這裏是我的代碼:在symfony2的實體字段中填充數據?
<?php
namespace Projects\ProjectsBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpFoundation\Response;
class MilestonesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('description')
->add('dueDate','datetime',array('label' => false,'data'=>new \DateTime(),'attr'=>array('style'=>'display:none;')))
->add('companyName', 'entity', array('class' => 'ClientsClientsBundle:Company','query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.id', 'ASC');
},
'label' => 'Company id',
'property' => 'companyName',
))
->add('firstname', 'entity', array('class' => 'ClientsClientsBundle:Clients','query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.id', 'ASC');
},
'label' => 'Client id',
'property' => 'firstname',
))
->add('isPrivate','choice', array('choices' => array('yes' => 'yes', 'no' => 'no')))
->add('startedAt','datetime',array('label' => false,'data'=>new \DateTime(),'attr'=>array('style'=>'display:none;')))
->add('completedOn','datetime',array('label' => false,'data'=>new \DateTime(),'attr'=>array('style'=>'display:none;')))
->add('createdDatetime','datetime',array('label' => false,'data'=>new \DateTime(),'attr'=>array('style'=>'display:none;')))
->add('updatedDatetime','datetime',array('label' => false,'data'=>new \DateTime(),'attr'=>array('style'=>'display:none;')))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Projects\ProjectsBundle\Entity\Milestones'
));
}
public function getName()
{
return 'projects_projectsbundle_milestonestype';
}
}
,這裏是我的編輯形式:
<form action="{{ path('milestones_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
<input type="hidden" name="_method" value="PUT" />
{{ form_widget(edit_form) }}
<p>
<button type="submit" class="btn btn-success">Next <i class="icon-chevron-right"></i></button>
</p>
</form>
如果你的var_dump在query_builder功能/模具,它說明了什麼? – acrobat
您是否可以顯示您的控制器操作,請致電表格 – pbenard