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
8e8903ef
Commit
8e8903ef
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
update docs
parent
1c35c577
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-6
4 additions, 6 deletions
README.md
docs/_index.md
+89
-0
89 additions, 0 deletions
docs/_index.md
with
93 additions
and
6 deletions
README.md
+
4
−
6
View file @
8e8903ef
#
ldap.class.php
#
TinyRouter
A PHP class that I use
*
for authentication of user logins
*
CRUD actions on ldap nodes
Axels first php class of a router.
Institute for Medical Education; University of Bern
Source:
<https://git-repo.iml.unibe.ch/iml-open-source/tinyrouter-php-class/>
License: GNU GPL 3
see
[
docs
](
docs/
)
\ No newline at end of file
see
[
docs
](
docs/
)
This diff is collapsed.
Click to expand it.
docs/_index.md
0 → 100644
+
89
−
0
View file @
8e8903ef
# TinyRouter
Axels first php class of a router.
## Installation
Copy the file
*tinyrouter.class.php*
somewhere into your project.
## Example
```
php
// load the class
require_once
(
'../classes/tinyrouter.class.php'
);
// define routes
$aRoutes
=
[
[
"/config"
,
"get_config"
],
[
"/config/@var"
,
"get_config_var"
],
[
"/apps"
,
"listapps"
],
[
"/apps/@appid:[0-9a-f]*"
,
"acess_appdata"
],
[
"/apps/@appid:[0-9a-f]*/@what:[a-z]*"
,
"acess_appdata"
],
// ^ ^
// | |
// route callback (string|array|... any type you want to get back)
// string = folder
// @var = set a variable
// @var:regex = set variable if it matches the given regex
];
// take an url ... or use the request uri if you have pretty urls
$sApiUrl
=
isset
(
$_GET
[
'request'
])
&&
$_GET
[
'request'
]
?
$_GET
[
'request'
]
:
false
;
// init the class
$oRouter
=
new
tinyrouter
(
$aRoutes
,
$sApiUrl
);
// it is the same like
// $oRouter=new tinyrouter();
// $oRouter->setRoutes($aRoutes);
// $oRouter->setUrl($sApiUrl);
// get the last matching route
$aFoundRoute
=
$oRouter
->
getRoute
();
if
(
!
$aFoundRoute
){
header
(
'HTTP/1.0 400 Bad request'
);
die
(
'<h1>400 Bad request</h1>'
);
}
// ... continue
```
The getRoute() method returns an array
*
with the matching route
*
name of the callback
*
vars on parts with starting @ chars
```
txt
// on url /apps/12345/meta
Array
(
[route] => /apps/@appid:[0-9a-f]*/@what:[a-z]*
[callback] => acess_appdata
[vars] => Array
(
[appid] => 12345
[what] => meta
)
)
```
If no route matches - or a variable did not match a required regex - then getRoute() returns
*false*
.
Maybe the keys of the array change in future. You can access the data with specialized getter functions:
```
php
// get the fallback
$sAction
=
$oRouter
->
getCallback
();
// all vars
$aAllvars
=
$oRouter
->
getVars
();
// get single vars
$sAppId
=
$oRouter
->
getVar
(
'appid'
);
$sWhat
=
$oRouter
->
getVar
(
'what'
);
```
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