how to use slim redirect(如何使用纤薄重定向)
问题描述
我有问题.我正在使用 slim 并且我的主页有路线:
I have a problem. I am using slim and I have route for my main page:
$app->get('/', function() use ($app) { ...
在我的一个控制器中,我想重定向到主页,所以我写了
In one of my controllers I want to redirect to the main page, so I write
$app->response->redirect('/', 303);
但是我没有重定向到/"路由,而是重定向到我的本地服务器的根目录,它是 http://localhost/
But instead of redirection to the '/' route I'm getting redirected to the root of my local server which is http://localhost/
我做错了什么?我应该如何使用重定向方法?
What am I doing wrong? How should I use redirect method?
推荐答案
Slim 允许您命名路由,然后使用 urlFor()
根据此名称重定向回它们.在您的示例中,将您的路线更改为:
Slim allows you to name routes, and then redirect back to them based upon this name, using urlFor()
. In your example, change your route to:
$app->get('/', function() use ($app) { ... })->name("root");
然后你的重定向变成:
$app->response->redirect($app->urlFor('root'), 303);
有关详细信息,请参阅 Slim 文档中的路由助手.
See Route Helpers in the Slim documentation for more information.
这篇关于如何使用纤薄重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用纤薄重定向


基础教程推荐
- php中的PDF导出 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01