简体   繁体   中英

Javascript redirect: script in symfony route not working

The page I from where I redirect:

<a class="uk-overlay" href="{{ path("shot.view",{"id" : id})  }}">
    <img class="uk-border-rounded" src="{{ largeSquare(shot) }}">
    <div class="uk-overlay-area uk-border-rounded">
        <div class="uk-align-right uk-margin-small-top">

            {% if is_granted('ROLE_USER') %}

                {% if app.user.isOwnStar( id ) %}
                    <button class="uk-icon-button uk-icon-star uk-margin-small-right" style="background: #00a8e6;"></button>
                {% else %}
                    <button class="uk-icon-button uk-icon-star uk-margin-small-right" onclick="window.location='{{ path("shot.giveStar",{"id" : id})  }}'"></button>
                {% endif %}

                {% if app.user.isOwnFavorite( id ) %}
                    <button class="uk-icon-button uk-icon-heart uk-margin-small-right" style="background: #d32c46;"></button>
                {% else %}
                    <button class="uk-icon-button uk-icon-heart uk-margin-small-right" onclick="window.location='{{ path("favorite.add",{"id" : id}) }}'"></button>
                {% endif %}

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

This is a image with an anchor and an overlay which containts some links. Because it is impossible to do nested anchors, i setup this links a buttons with javascript redirect.

The main problem is, that the called symfony route's (from the buttons) script is not executed:

public function giveStarAction(Application $app, Request $request, $id)
{
    $msg = $this->shotManager->giveStar($app['user']->getId(),$id);
    $app['session']->getFlashBag()->add('info', $msg );
    exit;
    return $app->redirect( $app->path('shot.view', array('id' => $id) ) );
}

eg Route for path("shot.giveStar",{"id" : id})

The first three lines were ignored, only the redirect command is executed ...

What do I have to change, that the code is executed before redirect?

Its

window.location.href = '' 
// or
window.location.replace("")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM