retamayo/vector

A routing library for php

1.0.1 2024-01-17 01:17 UTC

This package is auto-updated.

Last update: 2025-04-17 04:33:02 UTC


README

A simple and easy to use php routing library

How to use

Install using composer

composer require retamayo/vector

Note: do the following steps on the index file.

Include the autoloader

include "vendor/autoload.php";

Use the namespace

use Retamayo\Vector\Vector;

Get Instance of Vector

$vector = Vector::getInstance();

Run the router

$vector->run();

Add routes to the newly generated routes file

// add static routes
$this->get('/route_name', 'path_to_file');
// add callback routes
$this->get('/route_name', function () {
    echo "Hello World!";
});
// add dynamic routes
$this->get('/route_name/{slug}', function ($slug) {
    echo "Hello " . $slug;
});

You can edit the default 404 rout in the routes config file Note: when working with the config files do not change any name of the defined constants you can change their value but not the name.

define('DEFAULT_404', 'path_you_like');