I am trying to implement a helper function which helps me sort of 'add' routes (which map to controllers/actions) in an MVC application.
My index.php file looks like this.
// use block
use App\Router;
use App\Config;
use App\Core\Database;
use App\Bootstrap;
// dependencies
$router = new Router;
$config = new Config;
$database = new Database($config);
$bootstrap = new Bootstrap($router, $database);
// routes
require '../App/Routes.php';
$bootstrap->router->dispatch($_SERVER['QUERY_STRING']);
And my 'routes' file has one route in it, my routes look like this.
$bootstrap->router->add('/home', ['controller' => 'home', 'action' => 'index']);
I would prefer to simply add roots into my file like this...
route('/home', ['controller' => 'home', 'action' => 'index']);
So I need to make a helper function
question
Thanks to psr-4 autoloading I know how to pull in classes whenever I need them, however this is less clear when it comes to plane old functions. How can I cleanly add my helper functions into my MVC Framework without adding require files everywhere?
Many thanks in advance for your time and consideration!