dev-master
9999999-devSimple routing package for PHP.
MIT
The Requires
- php >=5.3.3
- symfony/yaml *
The Development Requires
by Habib Bargaoui
mvc routing controller routes light-weight beginner-friendly
Simple routing package for PHP.
Simple and easy-to-use router built for beginners and light-weight projects., (*2)
This package is compliant with [PSR-2], (*3)
Via Composer ``` bash $ composer require hoben/simple-routes, (*4)
Requirements -------- * PHP ^5.5.9 | >=7.0.8 * Symfony/yaml: ^3.4 Features -------- * Create routes defined in yaml files * You can also add routes in code with the function add of the class Router.php * You can filter routes by methods ( GET, POST, PUT ,DELETE,...) ### Adding routes with yaml file (routes.yaml) ```yaml "Dashboard": url: / controller: indexController action: index method: GET "Test Page": url: / controller: indexController action: showTest method: POST "default": controller: defaultController action: show404
```php5 $router = new Router(); $router->setBasePath('my-app/'); // Example: for www.localhost/my-app $router->setControllersPath('src/controllers/'); // Example: for controllers in www.localhost/my-app/src/controllers $router->setConfigPath('yaml-file-path/routes.yaml') // The yaml file path $router->match();, (*5)
### Adding routes with PHP code ```php5 use Hoben\SimpleRoutes\Router; $router = new Router(); $route->add('/products', 'ProductController', 'getProducts', 'GET'); $route->add('/product', 'ProductController', 'getProduct', 'GET'); $route->add('/product', 'ProductController', 'addProduct', 'POST'); $route->add('/product', 'ProductController', 'updateProduct', 'PUT'); $router->setBasePath('my-app/'); // Example: for www.localhost/my-app $router->setControllersPath('src/controllers/'); // Example: for controllers in www.localhost/my-app/src/controllers $router->match();
Create a simple .htaccess file on your root directory if you're using Apache with mod_rewrite enabled., (*6)
Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)$ index.php [NC,L]
If you're using nginx, setup your server section as following:, (*7)
server { listen 80; server_name mywebsite.dev; root /var/www/mywebsite/public; index index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_intercept_errors on; } }
The MIT License (MIT). Please see License File for more information., (*8)
Simple routing package for PHP.
MIT
mvc routing controller routes light-weight beginner-friendly