1. Go to this page and download the library: Download danidoble/routing 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/ */
danidoble / routing example snippets
use Symfony\Component\ErrorHandler\Debug;
use Danidoble\Routing\Route;
use Danidoble\Routing\Testing;
thub.com/symfony/error-handler)
Debug::enable();
$base_path = __DIR__ . DIRECTORY_SEPARATOR; // base path of your project
$base_view_path = env('APP_VIEW_DIR','views'); // route of your directory of views
\Danidoble\Routing\View::$BASE_VIEW_PATH = $base_path . env('APP_VIEW_DIR'); // example: /home/your/project/views
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__");
$dotenv->load();
$routes = new Route();
//add routes
$routes->add('/', [Testing::class, 'index'])->setMethods(['GET','POST']); //only get and post allowed
$routes->add('/help', [Testing::class, 'index'])->setMethods('GET'); //only get allowed
$routes->add('/danidoble', [Testing::class, 'index', 'a']); // all methods allowed
// dispatch
$routes->dispatch();
$path = "/lorem";//route slug
$controller = \Danidoble\Routing\Testing::class; // class/controller
$method = "index"; // method to execute
$route_name = "example_route"; // name of route
$routes->add($path,[$controller,$method,$route_name]);
class Testing extends \Danidoble\Routing\Controller
{
public function index()
{
//dump($this->getParent());
//dump($this->param('demo'));
dump($this->getParams());
}
}
public function __construct(RequestContext $_context, RouteCollection $_routes, UrlMatcher $_matcher, Route $_parent)
{
parent::__construct($_context, $_routes, $_matcher, $_parent);
// ... your code here
}
__construct()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.