jfm / simple-mvc-route-attributes-package
A little package for the pedagogical PHP MVC framework owned by Wild Code School. Used for educational purpose only
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/jfm/simple-mvc-route-attributes-package
Requires
- symfony/var-dumper: ^7.1
README
Description
This package is for the Wild Code School Simple MVC project. It allows to add attributes on all the Controller methods to define the route.
Installation
composer require jfm/simple-mvc-route-attributes
After the installation, you need to replace the all content of the src/routing.php file with the following:
<?php use Jfm\SimpleMvcRouteAttributesPackage\Routing\RouteLoader; RouteLoader::getInstance()->loadRoutes();
Usage
You can now use the #[Route] attribute on all your Controller methods to define the route.
<?php namespace App\Controller; use JFM\SimpleMVCRouteAttributes\Route; class HomeController extends AbstractController { #[Route('/')] public function index() { // ... } // ... }
<?php namespace App\Controller; use JFM\SimpleMVCRouteAttributes\Route; class ItemController extends AbstractController { #[Route('/items')] public function index() { // ... } #[Route('/items/show')] public function show() { // ... } // ... }
That's it!