Routing
Creating a Route
Place of routing files
modules/{Module}/etc/routing/
so if your moudule is Foo
, open your routing folder like this
modules/Foo/etc/routing/;
open the file frontend.json
- beneath the existing rule, add your own.
- To keep it simple at start, just copy the existing rule of
"/"
and add it beneath as route"/foo/"
- see route example. - now you can call the url
http://{whatever}/foo/
individual routing files
you can create you own *.json
routing file, for example foo.json
and edit your route in that file.
If you want to create routes for an API, it then makes sense to create a file called api.json
and write all your api routes inside that file.
route example: adding route /foo/
"/foo/": {
"query": "module=Foo&c=index&m=foo",
"title": "Foo",
"template": {
"layout": "Frontend/layout/index.tpl",
"var": {
"set": {
"sCss": "",
"sJs": ""
},
"load": {
"sMainmenu": "Frontend/layout/menu.tpl",
"sContent": "Frontend/content/index.tpl",
"sHeader": "Frontend/layout/header.tpl",
"sNoscript": "Frontend/content/_noscript.tpl",
"sCookieConsent": "Frontend/content/_cookieConsent.tpl",
"sFooter": "Frontend/layout/footer.tpl"
}
},
"sStyle": [
],
"sScript": [
]
}
}
Wildcard routing
per default all routings are restricitv
e.g. the route /foo/
- you can only call
/foo/
- you can not call
/foo/bar/
activating wildcard routing
therefore, just add *
after the route.
e.g. the route /foo/*
- you can call
/foo/
- you can call
/foo/bar/
- you can call
/foo/bar/baz/...
The reserved routing file .myMVC.json
- myMVC ist just looking for one file in the folder:
.myMVC.json
- do not edit this file
- this file is a dotfile, means that it is a so called hidden file
- this file combines all other
*.json
routing files found in the directory - *this file will automatically be updated each time you edit your `.json` files**
This is myMVC default behaviour: Activating by Event Listener
'mvc.reflex.reflect.targetObject.before' => array(
function(\MVC\DataType\DTArrayObject $oDTArrayObject) {
\MVC\Router::createFinalJson();
}
),
Get Information
Routing
Get complete Routing as Array
command
Router::getRouting();
alternative
Registry::get ('MVC_ROUTING');
result
array(1) {
["/"]=>
array(6) {
["query"]=>
string(30) "module=Foo&c=index&m=index"
["title"]=>
string(7) "Foo"
["template"]=>
array(4) {
["layout"]=>
string(25) "Frontend/layout/index.tpl"
["var"]=>
array(2) {
["set"]=>
array(2) {
["sCss"]=>
string(0) ""
["sJs"]=>
string(0) ""
}
["load"]=>
array(6) {
["sMainmenu"]=>
string(24) "Frontend/layout/menu.tpl"
["sContent"]=>
string(26) "Frontend/content/index.tpl"
["sHeader"]=>
string(26) "Frontend/layout/header.tpl"
["sNoscript"]=>
string(30) "Frontend/content/_noscript.tpl"
["sCookieConsent"]=>
string(35) "Frontend/content/_cookieConsent.tpl"
["sFooter"]=>
string(26) "Frontend/layout/footer.tpl"
}
}
["sStyle"]=>
array(0) {
}
["sScript"]=>
array(0) {
}
}
["path"]=>
string(1) "/"
["class"]=>
string(24) "Foo\Controller\Index"
["method"]=>
string(5) "index"
}
}
Get complete Routing as JSON
command
Router::getRoutingJson();
alternative
json_encode(Registry::get('MVC_ROUTING'))
result
string(523) "{"\/":{"query":"module=Foo&c=index&m=index","title":"Foo","template":{"layout":"Frontend\/layout\/index.tpl","var":{"set":{"sCss":"","sJs":""},"load":{"sMainmenu":"Frontend\/layout\/menu.tpl","sContent":"Frontend\/content\/index.tpl","sHeader":"Frontend\/layout\/header.tpl","sNoscript":"Frontend\/content\/_noscript.tpl","sCookieConsent":"Frontend\/content\/_cookieConsent.tpl","sFooter":"Frontend\/layout\/footer.tpl"}},"sStyle":[],"sScript":[]},"path":"\/","class":"Foo\\Controller\\Index","method":"index"}}"
Get current Routing as Array
command
Router::getRoutingCurrent()
alternative
Registry::get ('MVC_ROUTING_CURRENT');
result
array(6) {
["query"]=>
string(30) "module=Foo&c=index&m=index"
["title"]=>
string(7) "Foo"
["template"]=>
array(4) {
["layout"]=>
string(25) "Frontend/layout/index.tpl"
["var"]=>
array(2) {
["set"]=>
array(2) {
["sCss"]=>
string(0) ""
["sJs"]=>
string(0) ""
}
["load"]=>
array(6) {
["sMainmenu"]=>
string(24) "Frontend/layout/menu.tpl"
["sContent"]=>
string(26) "Frontend/content/index.tpl"
["sHeader"]=>
string(26) "Frontend/layout/header.tpl"
["sNoscript"]=>
string(30) "Frontend/content/_noscript.tpl"
["sCookieConsent"]=>
string(35) "Frontend/content/_cookieConsent.tpl"
["sFooter"]=>
string(26) "Frontend/layout/footer.tpl"
}
}
["sStyle"]=>
array(0) {
}
["sScript"]=>
array(0) {
}
}
["path"]=>
string(1) "/"
["class"]=>
string(24) "Foo\Controller\Index"
["method"]=>
string(5) "index"
}
Get Route Index On Key
command
Router::getRouteIndexOnKey(
'query',
'module=Foo&c=index&m=index'
);
- searches in Routing for key
query
with valuemodule=Foo&c=index&m=index
result
string(1) "/"
Request
Get Current Request
command
Request::getCurrentRequest();
result
array(6) {
["scheme"]=>
string(4) "http"
["host"]=>
string(14) "webbixx4.local"
["path"]=>
string(1) "/"
["requesturi"]=>
string(1) "/"
["protocol"]=>
string(7) "http://"
["full"]=>
string(22) "http://webbixx4.local/"
}
Get whitelisted Parameters as Array
command
Request::getWhitelistParamArray();
result
array(1) {
["GET"]=>
array(4) {
["module"]=>
array(2) {
["regex"]=>
string(16) "/[^[:alnum:]]+/u"
["length"]=>
int(50)
}
["c"]=>
array(2) {
["regex"]=>
string(16) "/[^[:alnum:]]+/u"
["length"]=>
int(50)
}
["m"]=>
array(2) {
["regex"]=>
string(17) "/[^[:alnum:_]]+/u"
["length"]=>
int(50)
}
["a"]=>
array(2) {
["regex"]=>
string(71) "/[^\p{L}\p{M}\p{Z}\p{S}\p{N}\p{Pd}\p{Pc}\p{Ps}\p{Pe}\p{Pi}\p{Pf}\|']+/u"
["length"]=>
int(256)
}
}
}
Set whitelisted Parameters as Array
here you can define filters vor variables - what to allow to pass through.
configuration example
$aParam = array ('GET' => array (
'module' => array (
'regex' => '/[^[:alnum:]]+/u', 'length' => 50,
),
'c' => array (
'regex' => '/[^[:alnum:]]+/u', 'length' => 50,
),
'm' => array (
'regex' => '/[^[:alnum:_]]+/u', 'length' => 50,
),
'a' => array (
'regex' => '/[^\\p{L}\\p{M}\\p{Z}\\p{S}\\p{N}\\p{Pd}\\p{Pc}\\p{Ps}\\p{Pe}\\p{Pi}\\p{Pf}\\|\']+/u',
'length' => 256,
),
),
);
command
Request::setWhitelistParamArray($aParam);
Get Query
command
Request::getInstance()->getQueryArray()
result
array(3) {
["POST"]=>
array(0) {
}
["COOKIE"]=>
array(1) {
["myMVC_cookieConsent"]=>
string(4) "true"
}
["GET"]=>
array(3) {
["module"]=>
string(7) "Webbixx"
["c"]=>
string(5) "Index"
["m"]=>
string(5) "index"
}
}
Path
Get Path
example: https://example.com/foo/bar/baz/?a=1
command
Request::getCurrentRequest()['path'];
result
string(13) "/foo/bar/baz/"
Get Path Array
example: https://example.com/foo/bar/baz/?a=1
command
Request::getInstance()->getPathArray()
result
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "bar"
[2]=>
string(3) "baz"
}
Get Requerst Uri
example: https://example.com/foo/bar/baz/?a=1
command
Request::getInstance()->getRequestUri()
result
string(13) "/foo/bar/baz/"