0
我想使用prePersist()掛鉤將獲取的對象設置爲準備好保留的對象。但我無法想象如何在Sonata Admin Bundle中使用教義。Symfony - Sonata抽象管理員和getDoctrine
這裏是我的代碼:
namespace ShareBundle\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class UserShareAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('quantity', 'text')
->add('user', 'sonata_type_model_list');
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('quantity');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('quantity')->addIdentifier('user')->addIdentifier('date');
}
public function prePersist($object)
{
$shareManager = $this->getDoctrine()->getManager()->getRepository('ShareBundle:Share');
$value = $shareManager->findOneBy(array(), array('date' => 'DESC'));
$object->setShare($value);
}
}
沒有人有任何想法怎麼辦呢?
謝謝!
你是什麼意思? –