如何在Sonata Admin Admin Controller中设置Flash消息 [英] How to set flash message in sonata admin Admin Controller

查看:194
本文介绍了如何在Sonata Admin Admin Controller中设置Flash消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在Sonata管理员捆绑包的管理控制器中设置Flash消息的方法,他们允许在CRUDController中将Flash消息设置为

im looking for a way to set flash message in admin controller of sonata admin bundle, they allow to set flash messages in CRUDController as

$this->get('session')->setFlash('sonata_flash_error', 'flash_batch_merge_error');

但不在管理控制器中,

这是我的管理员

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;

class ConfigAdmin extends Admin
{

protected function configureFormFields(FormMapper $formMapper)
{   

    $formMapper
        ->with('System Settings')
            ->add('Name','text', array('label' => "Configuration Name"))
            ->add('Language', 'choice', array(
                'label' => 'System Language',
                'choices' => array(0 => 'English', 1 => 'Swedish'),
                'preferred_choices' => array(0),
                ))
            ->add('commonmail','text', array('label' => "Common e-Mail"))
            ->add('dateformat','text', array('label' => "Date format"))
            ->add('currencyformat','text', array('label' => "Currency format"))
        ->end()
}

public function postUpdate($object) {

      // here i need to perform some validations and set flash message if there is an errror 

}

}

感谢您帮助

推荐答案

您正在谈论的是管理类,而不是控制器。

You are talking about an admin class, not a controller.

默认情况下这是不可能的。最好的方法是编写一个自定义的CRUDController(从默认值开始扩展)并在那里进行处理。

And this is not possible by default. Best way to do this is to write a custom CRUDController (extend from default one) and handle it there.

这篇关于如何在Sonata Admin Admin Controller中设置Flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆