本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\SessionInterface::getFlashBag方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionInterface::getFlashBag方法的具体用法?PHP SessionInterface::getFlashBag怎么用?PHP SessionInterface::getFlashBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Session\SessionInterface
的用法示例。
在下文中一共展示了SessionInterface::getFlashBag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFlash
/**
* @param string $type
* @param string $message
*/
protected function addFlash($type, $message)
{
if (!$this->session) {
$this->session = $this->getSession();
}
$this->session->getFlashBag()->set('notice', 'Session saved!');
}
示例2: updateSecondaryResources
public function updateSecondaryResources(ActivityParameters $parameters, \stdClass $stepStructure)
{
// Store current resources to clean removed
$existingResources = $parameters->getSecondaryResources();
$existingResources = $existingResources->toArray();
// Publish new resources
$publishedResources = array();
if (!empty($stepStructure->resources)) {
$i = 0;
foreach ($stepStructure->resources as $resource) {
$resourceNode = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneById($resource->resourceId);
if (!empty($resourceNode)) {
$parameters->addSecondaryResource($resourceNode);
$publishedResources[] = $resourceNode;
} else {
$warning = $this->translator->trans('warning_compl_resource_deleted', array('resourceId' => $resource->resourceId, 'resourceName' => $resource->name), "innova_tools");
$this->session->getFlashBag()->add('warning', $warning);
unset($stepStructure->resources[$i]);
}
$i++;
}
}
// Clean removed resources
foreach ($existingResources as $existingResource) {
if (!in_array($existingResource, $publishedResources)) {
$parameters->removeSecondaryResource($existingResource);
}
}
return $this;
}
示例3: publishAction
/**
* Publish path
* Create all needed resources for path to be played
*
* @Route(
* "/publish/{id}/{redirect}",
* name = "innova_path_publish",
* requirements = {"id" = "\d+"},
* options = {"expose" = true}
* )
* @Method({"GET", "PUT"})
*/
public function publishAction(Path $path, $redirect = false, Request $request)
{
$this->pathManager->checkAccess('EDIT', $path);
$response = array();
try {
$this->publishingManager->publish($path);
// Publish success
$response['status'] = 'OK';
$response['messages'] = array();
$response['data'] = json_decode($path->getStructure());
// Send updated data
} catch (\Exception $e) {
// Error
$response['status'] = 'ERROR';
$response['messages'] = array($e->getMessage());
$response['data'] = null;
}
if ($redirect) {
// That's not an AJAX call, so display a flash message and redirect the User
$message = 'OK' === $response['status'] ? 'publish_success' : 'publish_error';
$this->session->getFlashBag()->add('OK' === $response['status'] ? 'success' : 'error', $this->translator->trans($message, array(), 'path_wizards'));
return new RedirectResponse($request->headers->get('referer'));
}
return new JsonResponse($response);
}
示例4: testGetSetFlash
public function testGetSetFlash()
{
$this->assertNull($this->session->getFlash('notice'));
$this->assertEquals('default', $this->session->getFlash('notice', 'default'));
$this->session->getFlashBag()->add('notice', 'foo');
$this->session->getFlashBag()->add('notice', 'foo2');
// test that BC works by only retrieving the first added.
$this->assertEquals('foo', $this->session->getFlash('notice'));
$this->assertNull($this->session->getFlash('notice'));
}
示例5: testGetSetFlash
public function testGetSetFlash()
{
set_error_handler(array($this, "deprecationErrorHandler"));
$this->assertNull($this->session->getFlash('notice'));
$this->assertEquals('default', $this->session->getFlash('notice', 'default'));
$this->session->getFlashBag()->add('notice', 'foo');
$this->session->getFlashBag()->add('notice', 'foo2');
// test that BC works by only retrieving the first added.
$this->assertEquals('foo', $this->session->getFlash('notice'));
$this->assertNull($this->session->getFlash('notice'));
restore_error_handler();
}
示例6: redirect
public function redirect($url, $message = null)
{
if ($this->request->isXmlHttpRequest()) {
$json = array();
$json['redirect'] = $url;
if ($message) {
$json['message'] = $message;
}
return new JsonResponse($json);
} else {
if ($message) {
$this->session->getFlashBag()->add('success', $message);
}
return new RedirectResponse($url);
}
}
示例7: testFlashMessageWithCustomDomain
/**
* Test the flash manager get() method with a specified domain
*/
public function testFlashMessageWithCustomDomain()
{
// Given
$translator = $this->flashManager->getTranslator();
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', array('my_bundle_success_message' => 'My bundle success message!'), 'en', 'MyCustomDomain');
// When
$this->session->getFlashBag()->set('my_bundle_success', 'my_bundle_success_message');
$messages = $this->flashManager->get('success', 'MyCustomDomain');
$this->session->getFlashBag()->set('my_bundle_success', 'my_bundle_success_message');
$messagesWithoutDomain = $this->flashManager->get('success');
// Then
$this->assertCount(1, $messages);
$this->assertCount(1, $messagesWithoutDomain);
foreach ($messages as $message) {
$this->assertEquals($message, 'My bundle success message!');
}
foreach ($messagesWithoutDomain as $message) {
$this->assertEquals($message, 'my_bundle_success_message');
}
}
示例8: getGlobals
/**
* Returns all global assignable admin template variables
*
* @return array
*/
public function getGlobals()
{
return ['user' => $this->session->get('admin/user'), 'menu' => $this->session->get('admin/menu'), 'flashbag' => $this->session->getFlashBag()];
}
示例9: attachFlashBag
protected function attachFlashBag(SessionInterface $session)
{
if (!$this->flashLogger->isFlashBagAttached() && $session instanceof Session) {
$this->flashLogger->attachFlashBag($session->getFlashBag());
}
}
示例10: getGlobals
/**
* {@inheritdoc}
*/
public function getGlobals()
{
$scope = $this->session->get('admin/shop');
return ['user' => $this->session->get('admin/user'), 'menu' => $this->adminMenuProvider->getMenu(), 'shops' => $this->session->get('admin/shops'), 'activeContextId' => $scope['id'], 'flashbag' => $this->session->getFlashBag()];
}
示例11: reset
/**
* Resets the flash bag.
*/
public function reset()
{
$this->session->getFlashBag()->clear();
}
示例12: addToSession
/**
* @param string $key
* @param string $value
*
* @return void
*/
protected function addToSession($key, $value)
{
$this->session->getFlashBag()->add($key, $value);
}
示例13: __construct
protected function __construct(\Symfony\Component\HttpFoundation\Session\SessionInterface $session)
{
$session->start();
$this->flashBag = $session->getFlashBag();
return $this;
}
示例14: addFlash
/**
* @param string $type
* @param string $message
*/
protected function addFlash($type, $message)
{
$this->session->getFlashBag()->add($type, $message);
}
示例15: addUserFlash
/**
* Adds a flash message to the given session.
*
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* @param string $type
* @param string $message
*/
protected function addUserFlash(SessionInterface $session, $type, $message)
{
$session->getFlashBag()->add($type, $message);
}