1. Go to this page and download the library: Download krzysztof-magosa/saffron 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/ */
krzysztof-magosa / saffron example snippets
use KM\Saffron\RouterFactory;
$factory = new RouterFactory(
function ($collection) {
// configuration of routes goes here...
$collection->route('home')
->setUri('/')
->setTarget('HomeController');
}
);
use KM\Saffron\Request;
$request = Request::createFromGlobals();
use KM\Saffron\Request;
$request = new Request();
$request
->setUri($uri)
->setDomain($domain)
->setMethod($method)
->setHttps($https);
$result = $router->match($request);
// Building uri
$uri = $router->assemble('routeName', ['parameter1' => 'value1']);
// Building entire link (scheme + domain + uri)
$link = $router->assemble('routeName', ['parameter1' => 'value1'], true);
use KM\Saffron\Executor;
$executor = new Executor($result);
$executor->fire();
use KM\Saffron\Executor;
$executor = new Executor($result);
$executor
->setPreDispatch(
function ($controller, $method, $parameters) {
// do something before calling action
}
)
->setPostDispatch(
function ($controller, $method, $parameters) {
// do something after calling action
}
);
$executor->fire();