简体   繁体   English

奏鸣曲管理员 - 获取帖子数据

[英]sonata admin - get post data

I'm learning symfony2 and sonata admin and came across few problems and this is one of them.我正在学习 symfony2 和奏鸣曲管理,但遇到了一些问题,这就是其中之一。
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.我正在尝试在configureFormFields传递一些隐藏字段,但在提交表单后我无法使用上述方法访问它们。 I can see the request array but get('page') returns null.我可以看到请求数组,但get('page')返回 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();  
}  

也许有点晚了,但我希望它对某人有所帮助:

$this->getForm()->get('subobject')->getData()

Your attempt looks good.你的尝试看起来不错。 Looking at this post: https://groups.google.com/forum/#!topic/sonata-users/NS0mTAAHt7o看这篇文章: 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.检索所有提交的元素。

i'm not sure , but for mapped field you get the values directy in the parameter of your prepersist .我不确定,但是对于映射字段,您可以直接在 prepersist 的参数中获取值。

did you try to access your 'sub' values directly from $object ?您是否尝试直接从 $object 访问您的“子”值? like喜欢

$object->sub;

The $this->getRequest() works for symfony but i think it's a little bit different in sonata admin bundle .. $this->getRequest() 适用于 symfony 但我认为它在奏鸣曲管理包中有点不同..

Just an example for relation Office > Plan and looking for prop Plan.nameEn .只是关系Office > Plan和寻找道具Plan.nameEn一个例子。
In OfficeAdmin.php :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()) {}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM