PHPackages                             ngomafortuna/route-system-simple - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ngomafortuna/route-system-simple

ActiveLibrary[Framework](/categories/framework)

ngomafortuna/route-system-simple
================================

Simple route management system (Sistema simples de gerenciamento de rotas)

v0.0.3(7mo ago)117MITPHPPHP &gt;=8.0

Since Jun 1Pushed 7mo agoCompare

[ Source](https://github.com/ngomaf/route-system-simple)[ Packagist](https://packagist.org/packages/ngomafortuna/route-system-simple)[ RSS](/packages/ngomafortuna-route-system-simple/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Route system simple
===================

[](#route-system-simple)

Simple route management system (Sistema simples de gerenciamento de rotas)

Install
-------

[](#install)

```
composer require ngomafortuna/route-system-simple
```

Require
-------

[](#require)

Necessary PHP 8.0 or more (Necessário PHP 8.0 ou superior)

Exemple
-------

[](#exemple)

### Introdution

[](#introdution)

I will illustrate with a project with the following structure (Vou exemplificar com um projecto com a seguite extrutura):

- cacutenews
    - public
    - resources
        - library
        - views
    - src
        - controllers
        - models
        - services

### Start

[](#start)

Create the root directory `cacutenews`, enter the created directory and run the command `composer init` (Criar o directorio raiz `cacutenews`, entrar no directório criado e executar o comando `composer init`).

Edit the `composer.json` file, just the `prs-4` block, i.e. align `"App\\": "src/"` (Editar o arquivo `composer.json`, apenas o bloco da `prs-4` ou seja alinha `"App\\": "src/"`):

```
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
```

Still with composer install the component `composer require ngomafortuna/route-system-simple` (Ainda com composer intalar o componete `composer require ngomafortuna/route-system-simple`).

Update composer (Actualizar o composer `composer dump-autoload`).

Create the `index.php` file in the `public` directory and paste the code (Criar o arquivo `index.php` directório `public` nele cole o código):

```
use Ngomafortuna\RouteSystemSimple\Route;

define("PATH", dirname(__FILE__, 2)); // set 1 if index file is in root dir
define("URL", $_SERVER['HTTP_HOST']);
define("VIEWS", PATH . '/resources/views'); // path views dir
define("MAINDIR", PATH . '/src'); // path of the source code dir src
define("MAINAME", 'App'); // App is the dir of namespace, from composer.json

require_once PATH . '/vendor/autoload.php';

(new Route)->index();
```

On dir `cacutenews/vendor/ngomafortuna/route-system-simple/test/controllers/` copy the files `HomeController.php`, `NotFoundController.php` end `AboutController.php`(No directorio `cacutenews/vendor/ngomafortuna/route-system-simple/test/controllers/` copie os arquivos `HomeController.php`, `NotFoundController.php` e `AboutController.php`).

Past to dir `cacutenews/src/controllers/` (Cole-os no directório `cacutenews/src/controllers/`).

On dir `cacutenews/vendor/ngomafortuna/route-system-simple/test/views/` copy the files `error.php`, `home.php` end `master.php`(No directorio `cacutenews/vendor/ngomafortuna/route-system-simple/test/views/` copie os arquivos `about.php`, `error.php`, `home.php` e `master.php`).

Past to dir `cacutenews/resources/views/` (Cole-os no directório `cacutenews/resources/views/`).

Start project
-------------

[](#start-project)

In terminal access root dir `cacutenews` end execute this command (No terminal acesse o directório raiz `cacutenews-` e execute o comando abaixo):

```
php -S localhost:8000 -t public
```

In browser write `http://localhost:8000`

Did it work? (Funcionou?)

If it doesn't work, interpret the error returned and correct it (Caso não funcione interprete o erro retornado e corrija-o).

Create new routes
-----------------

[](#create-new-routes)

To add new routes follow these steps: (Para adicionar novas rotas siga os seguintes passos:)

1. Create the link on one of the pages or in the menu, for example (Crie o link em uma das páginas ou no menu, por exemplo):

```
Notícias
```

2. Create the route controller in `src/controllers/` with name `NoticeController.php` code for the controller (Crie o controller da rota em `src/controllers/` com nome `NoticeController.php` código para o controller):

```
