dev-master
9999999-dev https://github.com/blat/phencilHome-made PHP framework
MIT
The Requires
framework
Home-made PHP framework
Home-made PHP framework based on: * FastRoute * Symfony HttpFoundation component * Plates, (*1)
First, install using Composer:, (*2)
$ composer require blat/phencil
Then, create an index.php
file with the following contents:, (*3)
get('/', function() { return "Hello world!"; }); $app->run(); ``` Finaly, test using the built-in PHP server: ``` $ php -S localhost:8000 ``` ## Templates Update `index.php` to define your templates folder: ```php $app = new Phencil\App([ 'templates' => __DIR__ . '/templates', ]); ``` Add a new endpoint calling `render` method with the template name and some variables: ```php $app->get('/{name}', function($name) { return $this->render('hello', ['name' => $name]); }); ``` Create the template file `templates/hello.php`: ```phpHello = $name ?>!</p> , (*4)
Use getParam
method to access to GET
and POST
parameter:, (*5)
$app->get('/', function() { $foo = $this->getParam('foo'); });
Use getFile
method to access to FILES
. Result is an UploadedFile
:, (*6)
$app->get('/', function() { $file = $this->getFile('bar'); });
Redirect to another URL:, (*7)
$app->get('/', function() { $this->redirect('/login'); });
Serve a static file:, (*8)
$app->get('/download/', function() { $this->sendFile('/path/to/some-file.txt', 'pretty-name.txt'); });
Home-made PHP framework
MIT
framework