PHP code example of erickfirmo / router

1. Go to this page and download the library: Download erickfirmo/router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erickfirmo / router example snippets




  // Requires composer autoloader
  er = new \ErickFirmo\Router;

  // Defining optional settings

  // Load routes file
  



  $router->get('/examples', ExampleController::class, 'index', 'examples.index');
  $router->get('/examples/{id}', ExampleController::class, 'show', 'examples.show');
  $router->post('/examples/store', ExampleController::class, 'store', 'examples.store');
  $router->put('/examples/update/{id}', ExampleController::class, 'update', 'examples.update');
  $router->patch('/examples/update/{id}', ExampleController::class, 'update', 'examples.update');
  $router->delete('/examples/destroy/{id}', ExampleController::class, 'delete', 'examples.destroy');




  $router->setNamespace('App\Controllers\\');




  // Defining custom error page 404
  $router->notFoundView(__DIR__.'/../views/errors/404.php');




  // Creating array with request data
  $request = $_SERVER['REQUEST_METHOD'] == 'POST' ? $_POST : $_GET;

  // Passing request data
  $router->setRequest('request', $request);




  class ExampleController
  {
    public function myMethod(array $request, int $id)
    {
      echo $request['name'];
      echo $id;
    }

  }




  class ExampleController
  {
    public function myMethod(Object $request, int $id)
    {
      echo $request->name;
      echo $id;
    }

  }