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.
这篇关于如何使用纤薄重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用纤薄重定向
基础教程推荐
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
