Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tinyrouter-php-class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
tinyrouter-php-class
Commits
ca5f53c1
Commit
ca5f53c1
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
update docs
parent
dfda14cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/20_Usage.md
+14
-10
14 additions, 10 deletions
docs/20_Usage.md
with
14 additions
and
10 deletions
docs/20_Usage.md
+
14
−
10
View file @
ca5f53c1
...
...
@@ -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 @ char
s
*
the detected best
matching route
*
name of the callback
(read from 2nd value in your config)
*
vars
c
on
tains 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
f
allback
// get the
c
allback
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
);
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment