dev-master
9999999-dev https://github.com/exgalibas/Gina simple route based on yii2
MIT
The Requires
- php >=5.3.0
1.0
1.0.0.0 https://github.com/exgalibas/Gina simple route based on yii2
MIT
The Requires
- php >=5.3.0
a simple route based on yii2
A simple route for PHP based on yii2. You can get the source code easily by downloading file or using composer., (*1)
If you have composer, (*2)
composer require exgalibas/gin
Use the namaspace, (*3)
use \Exgalibas\Gin\Gin;
You can add the routing rules for specified http method like GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|ANY, (*4)
(new Gin)->get($pattern, $route)
The Pattern can be ordinary string, formatting regex with name or original regular expression like:, (*5)
The name in pattern will be used to replace the route if it has <name> or transmit as params, (*6)
// formatting regex (new Gin)->get("<function:(post|comment)>/<action:(create|update|delete)>/<id:(\d+)>", "<function>")
This rule only match "exgalibas/gin/login" and call function named "login", (*7)
//ordinary string (new Gin)->get("exgalibas/gin/login", "login")
Just be ordinary regular expression, match like "post/create/10" and call function named "create", (*8)
//original regular (new Gin)->get("(post|comment)\/(create|delete)\/\d+", "create")
The Route can be Closure, function name or formatting string like "class|function", (*9)
use \Exgalibas\Gin\Gin; $route = new Gin(); //example, match get url "post/10/create", call_user_func(["post", "create"], ["id" => 10]) $route->get("<class:(post|comment)>/<id:(\d+)>/<function:(create|update|delete)>", '<class>|<function>'); //delete route rule $route->deleteRule("<class:(post|comment)>/<id:(\d+)>/<function:(create|update|delete)>"); //example, match post url "exgalibas/login/10", call closure function([id=>10]) $route->post("exgalibas/login/<id:(\d+)>", function($params){...}) //example, match get url "exgalibas/login/joker", call login(["name" => "joker"]) $route->get("exgalibas/login/<name:joker>", "login") //parse the request $route->dispatch();
If dispatch error, exit "404", (*10)
a simple route based on yii2
MIT
a simple route based on yii2
MIT