Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sonata admin - get post data

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();  
}  
like image 926
trikess Avatar asked Feb 26 '14 16:02

trikess


1 Answers

Maybe a bit late but I hope it will be helpful for someone:

$this->getForm()->get('subobject')->getData()
like image 101
seltzlab Avatar answered Sep 21 '22 01:09

seltzlab