Download the PHP package cherry-project/router without Composer
On this page you can find all versions of the php package cherry-project/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cherry-project/router
More information about cherry-project/router
Files in cherry-project/router
Package router
Short Description Cherry-project Router
License MIT
Homepage https://github.com/cherry-framework/router
Informations about the package router
Cherry-Router
The Cherry-project Router
Including
Install from composer composer require cherry-project/router
Include Autoloader in your main file (Ex.: index.php)
Define application root directory
In your application you must have config.json file for storing app configuration settings and you must define his location:
config.json must contain path to routes.json and controllers directory
Get app config parameters and define it:
Notice: This approach will be replaced in the new version :))
It's time to configure routes file
The routes file is a json file, where object key is route unique name.
Each route must have path, method and action keys. Homepage route example:
Router file basic structure
Definitions for router keys:
- [RouteName] - Route unique name;
- path - Route url. (Ex.: For address http://www.example.com/homepage [URL] is homepage);
- method - Route HTTP Method. Allowed all HTTP methods;
- action - Route callback action. The firs part of action (before ::) is your controller (stored in CONTROLLERS_PATH). Controller is a simple PHP Class where [Controller] is Class name (Class name and class filename must have same names (Ex.: [Controller].php)). The second part of action key (after ::) is controllers (class) public method;
Your route path can use Placeholders. Placeholder is a template of your route.
Route example with placeholder:
There we have placeholder called {name} and we can get this value in controller:
2019 © Cherry-project