2017 © Pedro Peláez
 

library phencil

Home-made PHP framework

image

blat/phencil

Home-made PHP framework

  • Sunday, December 17, 2017
  • by blat
  • Repository
  • 1 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 27 % Grown

The README.md

Logo phencil

Home-made PHP framework based on: * FastRoute * Symfony HttpFoundation component * Plates, (*1)

Quick start

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`:
```php

Hello = $name ?>!</p> , (*4)

Access to request data

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');
});

Advanced response

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');
});

The Versions