carlbennett / php-mvc
A PHP micro-framework for use as a frontend and/or backend
Installs: 1 263
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php-64bit: >=8.0
- ext-curl: *
- ext-http: *
- ext-json: *
- ext-mbstring: *
- ext-mcrypt: *
- ext-pdo: *
Suggests
- ext-geoip: *
- ext-gmp: *
- ext-memcached: *
This package is auto-updated.
Last update: 2024-11-13 23:13:55 UTC
README
php-mvc is a PHP standard library used with @carlbennett's projects. The aspirations of this library are for a project website to include it as middleware.
Installation
This library is available via composer from packagist.
composer require carlbennett/php-mvc composer install
Usage
The following is an example of including this library in your project. This assumes you have already installed the library via composer.
<?php namespace MySuperAwesomeProject; use \CarlBennett\MVC\Libraries\GlobalErrorHandler; use \CarlBennett\MVC\Libraries\Router; use \CarlBennett\MVC\Libraries\Template; use \RuntimeException; // Can be used to route requests. $router = new Router( "\\MySuperAwesomeProject\\Controllers\\", "\\MySuperAwesomeProject\\Views\\" ); $router->addRoute( // URLs: /home, /home.htm, /home.html // pattern, model, view '#^/home(?:\.html?)?$#', 'Home', 'HomeHtml' ); $router->route(); $router->send(); // Custom template engine powered by pure PHP, utilizes include() and output buffers. $context = null; // empty context, used to pass state to template (new Template($context, 'HelloWorld'))->render(); // prints ./src/Templates/HelloWorld.phtml to the client. // A dynamic error handler. Prints JSON if display_errors is ON, a friendly html page if OFF. GlobalErrorHandler::createOverrides(); throw new RuntimeException('test');