[英]Javascript redirect: script in symfony route not working
我從中重定向的頁面:
<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>
這是帶有錨點和覆蓋層的圖像,其中包含一些鏈接。 因為不可能做嵌套錨,所以我將其設置為帶有JavaScript重定向的按鈕鏈接。
主要問題是,未執行被調用的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) ) );
}
例如path("shot.giveStar",{"id" : id})
前三行被忽略,僅重定向命令被執行...
我必須更改什么,以便在重定向之前執行代碼?
它的
window.location.href = ''
// or
window.location.replace("")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.