Home-made PHP framework based on:
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
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>
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');
});
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');
});