在symfony控制器中添加成功的flash消息并在Sonata Admin中显示它?

时间:2017-07-14 12:08:51

标签: php symfony sonata-admin flash-message

我想在symfony控制器(DefaultController)中添加一条flash消息,并将它作为常规flash消息显示在Sonata(Entity)Admin Class中。

$this->get('session')->getFlashBag()->add('success', 'Welcome to the Death Star, have a magical day!');

或者

$this->get('session')->getFlashBag()->add('sonata_flash_success', 'Welcome to the Death Star, have a magical day!');

在我的symfony控制器中,FlashBag将所有闪存消息放入队列:

Session {#95
  #storage: NativeSessionStorage {#94
    #bags: array:2 [
      "attributes" => AttributeBag {#90
        -name: "attributes"
        -storageKey: "_sf2_attributes"
        #attributes: & []
      }
      "flashes" => FlashBag {#89
        -name: "flashes"
        -flashes: & array:1 [
          "success" => array:3 [
            0 => "Welcome to the Death Star, have a magical day!!"
            1 => "Welcome to the Death Star, have a magical day!!"
            2 => "Welcome to the Death Star, have a magical day!!"
          ]
        ]
        -storageKey: "_sf2_flashes"
      }
    ]
    #started: true
    #closed: false
    #saveHandler: SessionHandlerProxy {#91
      #handler: NativeFileSessionHandler {#93}
      #wrapper: true
      #active: true
      #saveHandlerName: "files"
    }
    #metadataBag: MetadataBag {#92
      -name: "__metadata"
      -storageKey: "_sf2_meta"
      #meta: & array:3 [
        "u" => 1500032412
        "c" => 1500019957
        "l" => "0"
      ]
      -lastUsed: 1500032408
    }
  }
  -flashName: "flashes"
  -attributeName: "attributes"
}

Sonata(实体)管理类中的会话转储:

Session {#95 ▼
  #storage: NativeSessionStorage {#94 ▼
    #bags: array:2 [▼
      "attributes" => AttributeBag {#90 ▼
        -name: "attributes"
        -storageKey: "_sf2_attributes"
        #attributes: & array:1 [▶]
      }
      "flashes" => FlashBag {#89 ▼
        -name: "flashes"
        -flashes: & []
        -storageKey: "_sf2_flashes"
      }
    ]
    #started: true
    #closed: false
    #saveHandler: SessionHandlerProxy {#91 ▶}
    #metadataBag: MetadataBag {#92 ▶}
  }
  -flashName: "flashes"
  -attributeName: "attributes"
}

但在Sonata管理员中,既没有显示flash信息,也没有清空flash包。

0 个答案:

没有答案