sinevia / php-library-fastest
PHP 库 Fastest
v3.2.0
2019-01-14 22:48 UTC
README
最快的路由器
如何工作
简单而低调的路由器。
- 路由器会在 URL 中检查动作参数。如果没有找到,则默认为 "home"。
index.php?a=home (this is default)
index.php?a=register
-
执行请求动作对应的 PHP 函数。
-
动作函数与请求的动作同名,后缀为 "_action"。
(action: home => function: home_action)
(action: register => function: register_action)
- 短横线、空格和斜杠会被替换为下划线
(action: auth/login => function: auth_login_action)
(action: auth-login => function: auth_login_action)
安装
- 使用 composer(推荐)
composer require sinevia/php-library-fastest
- 手动。复制 fastest.php 文件,并使用 include_once 函数包含
使用方法
- 将以下行添加到路由器工作的位置。它可以作为应用的默认路由器,或一个独立的 PHP 网页。
// Add the actions require_once('../actions/home_action.php'); require_once('../actions/login_action.php'); // Execute the router \Sinevia::fastest();
- 可选地手动设置动作,例如,以拥有更友好的 URL
// Manually set the action and execute $uri = strtok($_SERVER["REQUEST_URI"],'?'); $result = \Sinevia::fastest(['action' => $uri]);
- 可选地以字符串形式输出结果,以便进一步手动处理
// Get the result as string and output $result = \Sinevia::fastest(['output_as_string' => true]); die($result);
- 示例函数
/** * The home function * route: ?a= or / */ function home_action { return 'Home'; } /** * The login function * route: ?a=login or /login */ function login_action { return 'Login'; }