PHP Slim 框架更改页面
PHP Slim framework changing page
我是 slim 和 MVC 的新手,我正在努力改变我网站上的页面。
目前使用下面的代码,当我访问我的索引页面时,它会将视图更改为我的项目页面,但是当它这样做时,它根本不会改变 URL。
$app->get('/', function($request, $response, $args) use($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
url 也保持 localhost/mywebsite
所以我的问题是如何让它随着视图一起更改 URL 以使其变为
localhost/mywebsite/项目
我有下面的代码,所以当有人访问那个 url 它会变成项目页面,但我不知道如何重定向用户。
$app->get('/projects', function($request, $response, $args) use ($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
当我尝试使用
$app->response->redirect('/projects', 303);
它说在 class 中找不到方法重定向。
我是不是遗漏了一些明显的东西,还是我完全错了。
谢谢!
您可以使用 $response
对象的 withRedirect()
函数
$app->get('/', function($request, $response, $args) {
return $response->withRedirect('/projetcs');
});
我是 slim 和 MVC 的新手,我正在努力改变我网站上的页面。
目前使用下面的代码,当我访问我的索引页面时,它会将视图更改为我的项目页面,但是当它这样做时,它根本不会改变 URL。
$app->get('/', function($request, $response, $args) use($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
url 也保持 localhost/mywebsite
所以我的问题是如何让它随着视图一起更改 URL 以使其变为
localhost/mywebsite/项目
我有下面的代码,所以当有人访问那个 url 它会变成项目页面,但我不知道如何重定向用户。
$app->get('/projects', function($request, $response, $args) use ($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
当我尝试使用
$app->response->redirect('/projects', 303);
它说在 class 中找不到方法重定向。
我是不是遗漏了一些明显的东西,还是我完全错了。
谢谢!
您可以使用 $response
对象的 withRedirect()
函数
$app->get('/', function($request, $response, $args) {
return $response->withRedirect('/projetcs');
});