0

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) ) );
}

e.g 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?

1 Answer 1

2

Its

window.location.href = '' 
// or
window.location.replace("")
Sign up to request clarification or add additional context in comments.

4 Comments

While your code might (or not) work it would be great if you add a brief explanation about the problem and how does your code solve it. As is it does not provide a full answer according to How to Answer
the code works for sure. if i replace the <button> tags with <a> and change the overlay from <a> to <div>, everything works.
i did it with: javascript:document.window.location.href - same problem
It's not document.window, it's window.document: w3schools.com/js/js_window.asp you might also try onclick="function() { window.location.href='xyz'; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.