require_once 'path/to/Router.php'; $router = new Router(); //Get the current request path $path = $router->GetPath(); //Use the path to determine the controller and action if ($path == '/login') { //Execute the login action of the Auth controller $auth = new AuthController(); $auth->login(); } else if ($path == '/register') { //Execute the register action of the Auth controller $auth = new AuthController; $auth->register(); }
require_once 'path/to/Router.php'; $router = new Router(); //Get the current request path $path = $router->GetPath(); //Add a route for the path '/hello' $router->addRoute('/hello', function() { echo "Hello World!"; }); //Execute the route $router->executeRoute($path);In this example, the GetPath method is used to extract the path from the request URL. The addRoute method is then used to add a new route for the path '/hello'. Finally, the executeRoute method is called with the extracted path as its parameter, which executes the corresponding function for the matching route. Overall, the PHP Router package library provides an easy-to-use and flexible way to handle routing in a PHP application.