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