What might be causing double requests to PHP?

Asked

Viewed 65 times

2

I am developing a system in Symfony2 and during the homologation process the client caught an error in which the system alerts keep repeating themselves.

The code used is this:

$objManager     = $this->getDoctrine()->getManager();
$objRepositorio = $objManager->getRepository( 'CIDSegurancaBundle:Usuario' );
$objUsuario     = $objRepositorio->find( $id );

if ( !$objUsuario ) {
  throw $this->createNotFoundException( 'Usuario nao encontrado para id ' . $id );
}

$objUserType = new UsuarioType( $objManager );
$objUserType->setIsEdit( true );
$objUserType->setUrlListagem( $this->generateUrl( 'usuarioListar', [ 'page' => 1, 'manterFiltro' => true ] ) );
$objUserType->setUrlListarEG( $this->generateUrl( 'usuarioAjaxListarEG' ) );
$objUserType->setUrlListarProcessos( $this->generateUrl( 'processoAjaxListarByMacroProcesso' ) );
$objUserType->setUrlListarSubProcessos( $this->generateUrl( 'subProcessoAjaxListarByProcesso' ) );

$objForm = $this->createForm( $objUserType, $objUsuario, [ 'attr' => [ 'id' => 'formUsuario' ] ] );

$objForm->handleRequest( $request );

$objUsuarioLogado = $this->getUser();
$objUsuario->setUsuarioAlteracao( $objUsuarioLogado );
$objUsuario->setDatAlt( System::getNow() );

if ( $objForm->isValid() ) {
  $objManager->persist( $objUsuario );
  $objManager->flush();

  $this->addFlash( 'info', 'Usuario alterado com sucesso!' );
  return $this->redirectToRoute( 'usuarioListar', [ 'page' => 1, 'manterFiltro' => 1 ] );
}

return $this->render( 'AppBundle:AcessControl:alterar.html.twig', [
  'title'  => 'Alterar Usuario',
  'form'   => $objForm->createView(),
  'perfis' => Perfil::getPerfisDisponiveis()
] );

The error I am getting is that "FLASH" messages are appearing repeated on the following pages.
When changing a user the client randomly receives the message: Usuário alterado com sucesso twice or more.
Apparently the requisition is being processed twice.

I did several local tests and could not reproduce the error in any way, so I’m guessing this is related to some configuration of the browser or the client server.

For approval the customer is using the Google Chrome 31.0.1650.57 m

Locally for testing I’m using the Google Chrome `40.0.2214.111 m

Does anyone have any idea what might be causing the problem?

Edition - 07/28/2015 at 08:30

amend.html.Twig

{% extends 'AppBundle:util:form_cad.html.twig' %}
{% block javascript %}
  {% javascripts '@AppBundle/Resources/public/js/AcessControl/cadastro.js' output='js/usuario/cadastro.js' %}
  <script type="text/javascript" src="{{ asset_url }}"></script>
  {% endjavascripts %}

  <script type="text/javascript">
    window.perfil = {
    {% for nome, id in perfis %}
    {{ nome }}: '{{ id }}',
    {% endfor %}
    };
  </script>
{% endblock %}

form_cad.html.Twig

{% extends 'AppBundle::base.html.twig' %}
{% form_theme form 'AppBundle:util:form.template.html.twig' %}
{% import "AppBundle:util:macro_form.html.twig" as macro %}

{% block conteudo %}
  {% spaceless %}
    <div class="col-md-12 col-lg-12">
      <div class="col-md-12 col-lg-10 col-lg-offset-1">
        <div class="panel panel-primary box-shadow-filter">
          <div class="panel-heading">
            <h3 class="panel-title text-center">{{ title }}</h3>
          </div>
          <div class="panel-body" id="formulario-cadastro">
            {% block panel_body %}
              {{ form_start(form) }}
              {{ form_widget(form) }}
              {{ form_end(form) }}
            {% endblock %}
          </div>
        </div>
      </div>
    </div>
  {% endspaceless %}
{% endblock %}

base.html.Twig

{% spaceless %}
  <!doctype html>
  <html lang="pt-br">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}"/>

    <title>{% block title %} {{ project_name }} {% endblock %}</title>

    {% stylesheets 'bundles/app/css/bootstrap.min.css'
    '@AppBundle/Resources/public/css/jquery-ui/jquery-ui.min.css'
    '@AppBundle/Resources/public/css/jquery-ui/jquery-ui.theme.min.css'
    'bundles/app/css/bootstrap-theme.min.css'
    '@AppBundle/Resources/public/css/layout.css'
    '@AppBundle/Resources/public/css/sweetalert.min.css'filter='cssrewrite' output='css/main.css' %}
    <link rel="stylesheet" href="{{ asset_url }}"/>
    {% endstylesheets %}

    {% block stylesheets %}{% endblock %}

    {% javascripts
    '@AppBundle/Resources/public/js/plugin/jquery-1.11.2.min.js'
    '@AppBundle/Resources/public/js/plugin/bootstrap.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery-ui.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery-mask.min.js'
    '@AppBundle/Resources/public/js/plugin/sweetalert.min.js'
    '@AppBundle/Resources/public/js/plugin/jquery.dataTables.min.js'
    '@AppBundle/Resources/public/js/util/modal.js'
    '@AppBundle/Resources/public/js/util/setup.js'
    '@AppBundle/Resources/public/js/util/util.js'
    '@AppBundle/Resources/public/js/util/processo.js'
    '@AppBundle/Resources/public/js/*.js'output='js/main.js' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

    {% block javascript %}{% endblock %}
  </head>
  <body>
  {% block navbar %}
    {% block navbar_main %}

      <div class="navbar-main">
        <div class="col-md-2 text-center logo-top">
          {% block image_top %}
            <a href="{{ path('homeListar') }}">
              <img src="{{ asset('bundles/app/images/logo_cliente_azul.gif') }}"/>
            </a>
          {% endblock %}
        </div>

        <div class="col-md-3 text-center project-name">
          {% block project_name_top %}
            {{ project_name }}
          {% endblock %}
        </div>

        <div class="col-md-1 pull-right"></div>
        <div class="col-md-3 hidden-xs hidden-sm pull-right">
          {% block user_top %}
            {% if app.user is not null %}

              <div class="divFotoUsuarioLogado">
                {% set nome = app.user.nomUsuario|split(' ') %}
                <img class="img-circle" src="http://URL-REMOVIDA/foto/{{ app.user.username }}.jpg"
                     title="" alt="" width="40" height="40"/>
              </div>
              <div class="divNomeUsuarioLogado">
                Ol&aacute;,<br/>
                <span class="text-uppercase">{{ nome[0] }}</span>
              </div>

            {% endif %}
          {% endblock %}
        </div>

      </div>
    {% endblock %}

    {% block navbar_menu %}
      {{ render(controller('AppBundle:Menu/Menu:accessMenu')) }}
    {% endblock %}

  {% endblock %}

  <div class="container-fluid">
    <div class="row">

    {% include 'AppBundle:util:session-alert.html.twig' %}

    {% block modal %}
      {{ include("AppBundle:util:modal-alert.html.twig") }}
    {% endblock %}

    {% block conteudo %}

    {% endblock %}
    </div>
  </div>

  </body>
  </html>
{% endspaceless %}
  • 1

    Put the view so the community can analyze.

  • cannot be the user by clicking 50x on save button?

  • Maybe. I asked the client about this and he informed me that he did not. I believe there is an error in the generated HTML or in the browser itself.

  • Look at the source code generated for the browser. If the javascript responsible for the action repeats, the action is executed twice :)

  • +1 why uses Symphony :)rsrsrs

  • Post the part of the template where you print the flashbag messages, please. :)

  • Have you solved it? If yes, post the answer and close the question, please :)

  • @Rodrigorigotti, I managed to solve it. The problem was form tags with empty action.

Show 3 more comments

1 answer

1


I noticed that some form tags were empty. Correctly putting the action in the forms solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.