PHP Classes

PHP Routes: Route HTTP requests to controller classes

Recommend this page to a friend!
  Info   View files Example   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-10-07 (21 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 54 All time: 10,482 This week: 106Up
Version License PHP version Categories
routes 1.0The PHP License5HTTP, PHP 5, Design Patterns
Description 

Author

This package can route HTTP requests to controller classes.

It can register URL path patterns to associate with controller classes.

The package can also process the current HTTP request and call the controller class that matches the first registered URL pattern.

The goal of this package is to implement a routing mechanism to present beautiful URLs.

With this mechanism, all requests are made in the public folder and then redirected to a specific file according to the route (URL) written.

Picture of António Lira Fernandes
Name: António Lira Fernandes <contact>
Classes: 11 packages by
Country: Portugal Portugal
Innovation award
Innovation award
Nominee: 3x

Winner: 2x

Example

<?php


/**
 * @autores Alf
 * @copyright 2020
 * @ver 1.0
 */


 
//echo $_SERVER['DOCUMENT_ROOT'] . _CAMINHO_CLASSES

//https://alexandrebbarbosa.wordpress.com/2019/04/19/phpconstruir-um-sistema-de-rotas-para-mvc-segunda-parte/

//echo __DIR__;

require __DIR__ . '/../config.php';
require
__DIR__ . '/../bootstrap.php';
require
__DIR__ . '/../src/helpers/helper_routes.php';
//define ("_CAMINHO_TEMPLATE", "../templates/opt2/");
//define ("_CAMINHO_TEMPLATE", "../templates/opt3/");

resolve();




?>


Details

routes

The goal of this package is to implement a routing mechanism to present beautiful URLs. With this mechanism, all requests are made in the public folder and then redirected to a specific file according to the route (URL) written.

version

Version 1.0 2023/03/06

install

  1. Copy all files to the website root.
  2. Update .htaccess for the actual configuration. Change line 3 to set for the url to public folder.

edit the routes file to match a route to a file. Each route or set of routes should correspond to a website service. In order to edit the routes.php file to make the correspondence you need to open the file and add the desired route and the corresponding service. For example, if you want to match the route "/my-route" to the "my-service" service, you can add the following line to the routes.php file:

Route::get('/my-route', 'MyService@index'); This will make it so that when a request is sent to the "/my-route" URL, the "MyService" service is invoked. You can also use route parameters and wildcards to make more complex matches. For more information on the routing system in PHP, please refer to the official documentation.


  Files folder image Files  
File Role Description
Files folder imagepublic (2 files)
Files folder imageroutes (1 file)
Files folder imagesrc (7 files, 1 directory)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file bootstrap.php Example Example script
Accessible without login Plain text file config.php Aux. Auxiliary script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  public  
File Role Description
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file index.php Example Example application script

  Files folder image Files  /  routes  
File Role Description
  Accessible without login Plain text file routes.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imagehelpers (1 file)
  Plain text file Connection.php Class Class source
  Plain text file Dispacher.php Class Class source
  Plain text file Request.php Class Class source
  Plain text file Response.php Class Class source
  Plain text file Route.php Class Class source
  Plain text file RouteCollection.php Class Class source
  Plain text file Router.php Class Class source

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file helper_routes.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:54
This week:0
All time:10,482
This week:106Up