我正在与Symfony应用程序交互的应用程序中工作,并从Symfony应用程序渲染使用FlashBag的模板。到目前为止,我所拥有的:
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
/*snipped code that creates a Symfony container*/
$container->enterScope('request');
$container->set('request', new \Symfony\Component\HttpFoundati
我正在构建一个symfony 3项目,我试图在提交表单后,在树枝模板中显示一个手电筒消息,通知用户表单已成功提交,但它不适合我!下面是控制器:
<?php
namespace EvalBundle\Controller;
use EvalBundle\Entity\SessionEvaluation;
use EvalBundle\Form\SessionEvaluationType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\C
渲染小枝模板时,我在控制器中设置了一条flash消息。如果有post操作,我想重定向到同一页,但更改闪光消息。
if ($request->isMethod('POST')) {
...
...
$this->get('session')->getFlashBag()->clear(); // Does not work
$this->get('session')->getFlashBag()->all(); // Does not work
$reques
我的问题
我应该返回什么样的响应,不会改变默认响应?或者,是否有更好的方法将记录器锁定为Login失败/凭据不足的异常?
详细信息
我找到了这篇文章,它指出您可以(在Symfony 2.4中)自定义身份验证失败或成功,如下所示:
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Se
我试着在设置好的会话闪存时做出反应,但总是选择其他路径。
Symfony 2.1.3
主计长:
$this->get('session')->getFlashBag()->set('contactActionNoticeError', 'Message not sent');
视图(尝试了“旧”和新样式),但我得到了bla2
{% if app.session.flashbag.has("contactActionNoticeError") or app.session.hasFlash("contact
我这里有个奇怪的东西。我已经复制了S4文档中的所有内容,但是它似乎并不像预期的那样工作。控制器代码:
// Adding a success type message
$this->addFlash("success", "This is a success message");
// Adding a warning type message
$this->addFlash("warning", "This is a warning message");
// Adding an error type message
我使用一个操作来显示和提交一个用createFormBuilder构建的表单。
public function fooBar(){
// ... creating form and stuff
// on first Request i want to use the FlashBag to hold a "Fill out !" message
// how to if here ? if(first request){
$this->get('session')->getFlashBag()->
我正在尝试设置来自ContactAction的闪光消息,然后在主页上重定向,但在它上面,我看不到我的闪光消息,可能我的会话被重置了?我能得到一些帮助吗,我是Symfony的初学者。
同时包含索引和联系函数的CoreController:
<?php
namespace OC\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class CoreController extends Controller
{
public function indexAction()
我有一个将值写入特定实体的表单,我试图通过控制器中的一个函数编辑信息,非常简单。
BancoController.php
<?php
namespace App\Controller;
use App\Entity\Banco;
use App\Form\BancoType;
use App\Repository\BancoRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoun
我为我的Symfony 5项目创建了一个登录表单。
当用户无法访问我的管理面板时,我希望将匿名用户重定向到自定义页面(而不是登录页面)。
应用程序控制器:
// TestController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGran
我正在开发我的Symfony2项目中的Json/AJAX实现。一切正常(模态、重定向等)但是我的"fire event“实现不是这样的。
这是我的代码:
$(document).trigger(data.content, [data.data]);
data.content包含事件的名称,在本例中为"lesson_editor.added_step“,data.data包含一个HTML。
我在jQuery库中得到错误Uncaught TypeError: undefined is not a function。对于Chrome调试器,上面的触发器就是导致它的那一行。
如果我用字
我使用的是实体框架6.1.1,当我在异步调用中使用自定义模型绑定时,它会抛出一个异常,因为子实体(Brand)并不是加载和强制的。我正在使用ninject,我更新到了最新版本( 3.2.2.0),下面是代码:
public class PlayerModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
v
我在这里读过很多关于这个话题的文章,但是我还是没有成功。
我正在使用Symfony version 2.2.3,目前我正在尝试在我的项目中使用闪光灯包,但由于某种原因,我在Twig模板中接收到一个空数组。
以下是我的控制器代码:
public function addProductAction($id) {
$session = $this->container->get('session');
// *** Some nive stuff here with session parameters **
$sess
我有一个容器来存放我所有的flashmessage,它位于for语句之外,即使没有可用的flash消息也会显示出来。 下面的代码很好地完成了它的工作,我只是想防止容器在没有闪烁的情况下被显示。我想找个法子做一个Twig来测试它。 <div class="flashMsgContainer">
{% for flash_message in app.session.flashBag.get('success') %}
{# more code #}
{% endfor %}
{% for flash_mess
嗨,我正在使用symfony,有时我需要使用ajax来避免页面的重新加载。我有两个实体," event“和"list”,我想将一些列表与事件关联起来,我的代码正确地使用ajax,但是在记录完之后,我想显示一条闪存消息,让用户理解操作已经完成。这里是我的jquery代码:
<script type="application/javascript">
$(".modal-body").hide();
$("#btnenr").click(function(){
var ev
我是symfony的新手,我尝试用form在我的基础上注册一个实体。表单如下所示: <?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\F