I'm new to slim and MVC and i'm trying to get my head around changing pages on my website.
Currently using the code below when I access my index page it will change the view to be my projects page, however when it does this it doesn't change the URL at all.
$app->get('/', function($request, $response, $args) use($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
The url also stays as localhost/mywebsite
So my question is how do I get it to change the URL along with the view so that it becomes
localhost/mywebsite/projects
I've got the below code so that when someone goes to that url it becomes the projects page but I can't figure out how to redirect the user.
$app->get('/projects', function($request, $response, $args) use ($app)
{
return $this->renderer->render($response, 'projects.phtml', $args);
});
When I tried using
$app->response->redirect('/projects', 303);
It says method redirect not found in class.
Am I missing something obvious or am I making this completely wrong.
Thanks!
You can use withRedirect()
function of $response
object
$app->get('/', function($request, $response, $args) {
return $response->withRedirect('/projetcs');
});