带有参数的 Slim Framework 重定向 [英] Slim Framework redirect with params

查看:61
本文介绍了带有参数的 Slim Framework 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用 Slim 框架,到目前为止一切都在现场.但是有一件事我似乎无法理解.发布表单后,我想重定向回同一页面,但它在 url 中使用了一个参数,我无法返回它.这是我目前所拥有的:

I'm using Slim framework for the first time, and so far everything is spot on. But there is one thing I can't seem to get my head around. After posting a form I would like to redirect back to the same page, but it uses a param in the url and I can't get back to it. This is what I have so far:

$app->post('/markets-:game', $authenticated(), function($game) use ($app) {

    $request = $app->request();

    $id = $request->post('game3');

    $app->flash('global', 'game added');
    $app->response->redirect($app->urlFor('games.markets', {"game:$id"}));

})->name('games.markets.post');

任何帮助将不胜感激.谢谢

Any help would be much appreciated. Thanks

推荐答案

urlFor 方法接受两个参数:

  1. 路线名称;
  2. 一个包含所有参数的关联数组(可选).

试试这个:

$app->response->redirect($app->urlFor('games.markets', array('game' => $id)));

这篇关于带有参数的 Slim Framework 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆