'MVC PHP - A better way to simplify my linking
I am looking for a way to create a solution to simplify my linking. On a site I am creating there will be multiple places (for example 15) where there will be a link to e.g. a privacy policy, and therefore when the URL to the policy changes I don't want to edit 15 different files, just change the URL in one place. I came up with this solution:
class PrivacyPolicy extends \Core\Controller
{
const PrivacyPolicyUrl = 'privacy-policy';
public function indexAction()
{
View::render('Privacy-policy/index.php', []);
}
}
and when I want to link to the privacy policy I do it like this
<a href="<?=ROOT?><?=App\Controllers\PrivacyPolicy::PrivacyPolicyUrl?>">Privacy policy</a>
But i don't feel like it's it.
Note: I don't want to create a file with paths for each page, but define the URLs locally as shown above. Is there a better way to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
