Skip to content
Snippets Groups Projects
Commit ca5f53c1 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update docs

parent dfda14cb
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ require_once('../classes/tinyrouter.class.php');
### Config
Define the routes as array elements.
Define the routes and its return values as array elements.
First item is a route. The 2nd item is something you get back as callback item of a matching route. Here are strings but you can define other variable types like objects here.
```php
......@@ -23,8 +23,9 @@ $aRoutes=[
[ "/apps/@appid:[0-9a-f]*/@what:[a-z]*", "acess_appdata" ],
// ^ ^
// | |
// route callback (string|array|... any type you want to get back)
// string = folder
// | callback
// route a string|array|...
// string = folder any type you want to get back
// @var = set a variable
// @var:regex = set variable if it matches the given regex
];
......@@ -62,9 +63,9 @@ The getRoute() method returns an array
* request url
* request method (GET|POST|PUT|DELETE|...)
* with the matching route
* name of the callback
* vars on parts with starting @ chars
* the detected best matching route
* name of the callback (read from 2nd value in your config)
* vars contains all variables coming from url parts starting with a @ char
```txt
// on url /apps/12345/meta
......@@ -86,12 +87,12 @@ Array
If no route matches - or a variable did not match a required regex - then getRoute() returns *false*.
### Other getters
### Specific getters
Maybe the keys of the array change in future. You can access the data with specialized getter functions:
Maybe the keys of the array above change in future. You can access the data with specialized getter functions:
```php
// get the fallback
// get the callback item only
$sAction=$oRouter->getCallback();
// all vars
......@@ -102,7 +103,7 @@ $sAppId=$oRouter->getVar('appid');
$sWhat=$oRouter->getVar('what');
```
You can get the nth element from the request url. In our example with index 0 you
You can get the nth element from the request url. In our example with index 0 you
get the 1st element which can be "config" or "apps".
```php
......@@ -121,4 +122,7 @@ To continue with the variables above: you maybe want to execute the method with
```php
$aData=$Obj->$sAction($sAppId, $sWhat);
// ...
header('Content-Type: application/json');
echo json_encode($aData);
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment