[英]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.
因为不可能做嵌套锚,所以我将其设置为带有JavaScript重定向的按钮链接。
The main problem is, that the called symfony route's (from the buttons) script is not executed: 主要问题是,未执行被调用的symfony路由(从按钮)的脚本:
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})
例如
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("")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.