Not a back-end guy by any means, but can navigate my way through the basics. My question is this, I have the below function for a benefits page I'm doing. Wanted to simplify the sub-pages versus creating multiple controller functions and route redirects. So I decided to go the URI as a variable route...not sure if this is clean way of doing it or not (usually I only go this route when dynamically creating pages via db). But it works.
If I go to website.com/benefits/{section} the IFs work as they should. However, if I go to website.com/benefits/ I get a 404 page - obviously. I have nothing to handle that request - only because I don't know how. How do I redirect to the home page is a user visits website.com/benefits/ and no uri (i.e. $section) was defined?
EDIT: Or would it be wise to just create a separate function benefits(){} function along with the one below? Is this good practice?
Controller function:
function benefits($section)
{
if($section == 'fitness')
{
echo('fitness page!');
}
elseif($section == 'health')
{
echo('health page!');
}
elseif($section == 'beauty')
{
echo('beauty page!');
}
elseif($section == 'sports')
{
echo('sports page!');
}
else
{
redirect('/');
}
}
redirect('/');is "redirect to the home page"? - anvoz