sinevia / php-library-fastest
PHP Library Fastest
v3.2.0
2019-01-14 22:48 UTC
README
Fastest router
How it works
Simple and unassuming router.
- The router checks for an action parameter in the URL. If not found assumes "home".
index.php?a=home (this is default)
index.php?a=register
-
Executes a PHP function for the requested action.
-
The action function has the same name as the requested action with the "_action" postfix.
(action: home => function: home_action)
(action: register => function: register_action)
- Dashes, spaces, and forward slashes are replaced with underscores
(action: auth/login => function: auth_login_action)
(action: auth-login => function: auth_login_action)
Installation
- Using composer (recommended)
composer require sinevia/php-library-fastest
- Manually. Copy the fastest.php file and use the include_once function to include
Usage
- Add the following line to where the router will be working. It can be the main router of the app, or a standalone PHP webpage.
// Add the actions require_once('../actions/home_action.php'); require_once('../actions/login_action.php'); // Execute the router \Sinevia::fastest();
- Optionally the action can be set manually, for instance to have nice URLs
// Manually set the action and execute $uri = strtok($_SERVER["REQUEST_URI"],'?'); $result = \Sinevia::fastest(['action' => $uri]);
- Optionally the result can be output as string to be processed manually further
// Get the result as string and output $result = \Sinevia::fastest(['output_as_string' => true]); die($result);
- Example functions
/** * The home function * route: ?a= or / */ function home_action { return 'Home'; } /** * The login function * route: ?a=login or /login */ function login_action { return 'Login'; }