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.
这篇关于如何使用纤薄重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用纤薄重定向


- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01