blat / phencil
This package is abandoned and no longer maintained.
No replacement package was suggested.
Home-made PHP framework
v0.2
2020-02-16 13:48 UTC
Requires
- illuminate/database: ^6.15
- league/plates: ^3.3
- nikic/fast-route: ^1.3
- symfony/http-foundation: ^5.0
This package is not auto-updated.
Last update: 2021-06-13 13:00:22 UTC
README
Home-made PHP framework based on:
Quick start
First, install using Composer:
$ composer require blat/phencil
Then, create an index.php
file with the following contents:
<?php require_once __DIR__ . '/vendor/autoload.php'; $app = new Phencil\App(); $app->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:
$app = new Phencil\App([ 'templates' => __DIR__ . '/templates', ]);
Add a new endpoint calling render
method with the template name and some variables:
$app->get('/{name}', function($name) { return $this->render('hello', ['name' => $name]); });
Create the template file templates/hello.php
:
<p>Hello <?= $name ?>!</p>
Access to request data
Use getParam
method to access to GET
and POST
parameter:
$app->get('/', function() { $foo = $this->getParam('foo'); });
Use getFile
method to access to FILES
. Result is an UploadedFile
:
$app->get('/', function() { $file = $this->getFile('bar'); });
Advanced response
Redirect to another URL:
$app->get('/', function() { $this->redirect('/login'); });
Serve a static file:
$app->get('/download/', function() { $this->sendFile('/path/to/some-file.txt', 'pretty-name.txt'); });