3
我想要構建一個特殊的窗體來管理LogEntry實體(從Loggable Behavioral)並處理實體回覆以允許管理員將某些實體恢復到舊版本。建立一個窗體來處理從Doctrine Loggable擴展的實體恢復
我試了下FormType生成與分配給特定LogEntry實體的版本的列表形式:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository as EntityRepository;
class LogItemVersionsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// In that point, I would need the entity assigned to that specific LogEntry to be able to load the diferent versions
$entity = $builder->getData();
//var_dump($data);
$builder
->add('version', 'entity', array(
'class' => 'Gedmo\Loggable\Entity\LogEntry',
'property' => 'version',
'query_builder' => function(EntityRepository $er) {
return $er->getLogEntriesQuery($entity);
},
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Gedmo\Loggable\Entity\LogEntry'
));
}
public function getName()
{
return 'zashost_zaspanelbundle_logitemversionstype';
}
}
但我有如下疑問:
- 的LogEntry有沒有方法來檢索記錄的對象。我應該創建一個繼承LogEntry的中間類來添加該方法嗎?請注意,分配給LogEntry的實體是可變的,所以我應該將該方法放在LogEntry實體類中?