1. Go to this page and download the library: Download redcatphp/route library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
redcatphp / route example snippets
class MyFrontOffice extends \\RedCat\\Route\\FrontOffice{
function \_\_construct(Router $router,Di $di){
parent::\_\_construct($router,$di);
$this->map([
['backend/','new:RedCat\\Plugin\\FrontController\\Backoffice'],
[['new:RedCat\\Route\\Match\\Extension','css|js|png|jpg|jpeg|gif'],'new:RedCat\\Plugin\\FrontController\\Synaptic'],
[['new:RedCat\\Plugin\\RouteMatch\\ByTml'.($this->l10n?'L10n':''),'','template'],'new:RedCat\\Plugin\\Templix\\Templix'.($this->l10n?'L10n':'')],
]);
}
function run($path,$domain=null){
if(!parent::run($path,$domain)){
http\_response\_code(404);
print "Page not found !";
exit;
}
return true;
}
}
use RedCat\\Route\\Match\\Prefix;
use RedCat\\Route\\Match\\Suffix;
use RedCat\\Route\\Match\\Regex;
use RedCat\\Route\\Match\\Extension;
$f = new MyFrontOffice();
$this->append(new Prefix('test/'),function($path){
print "My url start with 'test' followed by '$path'";
});
$this->prepend(new Prefix('test/more'),function($path){
print "My url start with 'test/more' followed by '$path'";
});
$f->append(new Suffix('.stuff'),function($path){
print "My url end with '.stuff' preceded by '$path'";
});
$this->append(new Prefix('test/'),function($path){
print "My url start with 'test' followed by '$path'";
},2);
$this->prepend(new Prefix('test/more'),function($path){
print "My url start with 'test/more' followed by '$path'";
},2);
$f->append(new Suffix('.stuff'),function($path){
print "My url end with '.stuff' preceded by '$path'";
},1);
// test/more is a string, consequently it will be wrapped automaticaly by Prefix object
$this->prepend('test/more',function($path){
print "My url start with 'test/more' followed by '$path'";
});
// string start with "/^" and end with "$/", consequently it will be wrapped automaticaly by Regex object
$this->append('/^blog/(\\w+)/(\\d+)$/',function($category, $id){
// if url is blog/php/200 it will print "php:200"
print $category.':'.$id;
});
$f->append('',function(){
print 'You are on home page !';
});
$f->append(['new:RedCat\\Route\\Match\\Suffix','.stuff'],function($path){
print "My url end with '.stuff' preceded by '$path'";
});
// Class instanciation and method
$f->append('hello',[['new:MyModuleClass'],'methodName']);
// Class instanciation with construct params and method
$f->append('hello',[['new:MyModuleClass',$param1ForInstanciation,$param2ForInstanciation],'methodName']);
// Class instanciation and invokation
// object will be invoked after instanciation using \_\_invoke magic method if exists
$f->append('hello','new:MyModuleClass');
//manual url
$f->run('test/');
//automatic current url
$f->runFromGlobals();
$url = new Url;
\# http:// or https://
$url->getProtocolHref();
\# mydomain.com
$url->getServerHref();
\# output integer number of port if different from default (80 for http and 443 for https)
$url->getPortHref();
\# root-path-of-redcat/
$url->getSuffixHref();
\# http://mydomain.com/root-path-of-redcat/
$url->getBaseHref();
\# http://mydomain.com/root-path-of-redcat/current-path/
$url->getLocation();
\# http://mydomain.com/root-path-of-redcat/
$url->getSubdomainHref();
\# http://fr.mydomain.com/root-path-of-redcat/
$url->getSubdomainHref('fr');
\# if current subdomain contain 2 character it will output them
$url->getSubdomainLang();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.