Reputation: 71
I'm learning symfony2 and sonata admin and came across few problems and this is one of them.
I've created an admin class which extends sonata admin and the below wouldn't work for me:
$this->getForm()->get('page')
or
$this->getRequest()->request->get('page')
I'm trying to pass some hidden fields in the configureFormFields
but I can't access them using the above after the form has been submitted. I can see the request array but get('page')
returns null. Also, the request array is multidimensional.
Any advice appreciated.
Simple example of what I'm trying to do is below:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('title')
->add(
'subobject',
'hidden',
array(
'mapped' => false,
'data' => 'sub'
)
)
;
}
public function prePersist($object)
{
$subobject_request = $this->getRequest()->request->get('subobject');
print_r($subobject_request); //is null
die();
}
Upvotes: 6
Views: 9089
Reputation: 954
Just an example for relation Office > Plan
and looking for prop Plan.nameEn
.
In OfficeAdmin.php
:
protected function configureFormFields(FormMapper $formMapper) {
$formMapper->add('plan', 'sonata_type_admin')
}
public function preUpdate($marina) {
if ($planName = $this->getForm()->get('plan')->get('name_en')->getData()) {}
}
Upvotes: 0
Reputation: 340
Maybe a bit late but I hope it will be helpful for someone:
$this->getForm()->get('subobject')->getData()
Upvotes: 6
Reputation: 1916
Your attempt looks good. Looking at this post: https://groups.google.com/forum/#!topic/sonata-users/NS0mTAAHt7o
I could successfuly use:
public function preUpdate($object)
{
$uniqid = $this->getRequest()->query->get('uniqid');
$formData = $this->getRequest()->request->get($uniqid);
var_dump($formData);exit;
}
to retrieve all submitted elements.
Upvotes: 4
Reputation: 1783
i'm not sure , but for mapped field you get the values directy in the parameter of your prepersist .
did you try to access your 'sub' values directly from $object ? like
$object->sub;
The $this->getRequest() works for symfony but i think it's a little bit different in sonata admin bundle ..
Upvotes: 0