Skip to content

This is a Easy Router component. Have automatic class loader. Runs the controller or file registered in the routes array according to the current uri

License

Notifications You must be signed in to change notification settings

suvarivaza/easy-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

EasyRouter

About

This is a Easy Router component. Have automatic class loader. Runs the controller or file registered in the routes array according to the current uri

Installation

Just download and include the library to your project.

include 'src/EasyRouter.php';
use Suvarivaza\ER\EasyRouter; // use namespace EasyRouter

Usage

  1. First, let's create an array with routes and register them.
  2. Create an object of the EasyRouter class.
  3. Execute the RUN method.

Example:


$routes = [
    '/' => [
        'controller' => 'HomeController', // You can specify the controller that will handle the request.
        'path' => 'controllers/' // And specify the path to the controller
    ],
    '/posts/' => [
        'file' => 'posts.php', // You can specify the file to which the request will be redirected.
        'path' => 'public/' // And specify the path to the handler file
    ],
    '/posts/show' => [
        'controller' => 'PostsController/show', // Also you can optionally specify the controller method
        'path' => 'controllers/'
    ],
    '/posts/edit' => [
        'controller' => 'PostsController/edit', // controller method
        'path' => 'controllers/'
    ],
    '/404' => [
        'file' => '404.php', //you can specify the path to your custom 404 file
        'path' => 'public/'
    ]
];

$router = new EasyRouter();
$router->run($routes, $_SERVER['REQUEST_URI']);

Method RUN gets two arguments: $router | array $uri | string

About

This is a Easy Router component. Have automatic class loader. Runs the controller or file registered in the routes array according to the current uri

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages