An open API service indexing awesome lists of open source software.

https://github.com/alextselegidis/phingle

📄 Single File App Template
https://github.com/alextselegidis/phingle

php single-file-app template

Last synced: about 1 year ago
JSON representation

📄 Single File App Template

Awesome Lists containing this project

README

          





Phingle



Phingle




Single File App Template


About •
Structure •
Develop •
License

![screenshot](phingle-snippet.png)

## About

**Phingle** is a simple yet practical single file app template file, that will allow to quickly implement utility
scripts for your server. It was created as a started point for very basic server side operations both locally or on
remote servers, as it aims to provide lightweight routing functionality and CDN based styling with Bootstrap.
**Attention: this is just a file template and no framework by any means.** You can copy it and create your own single
(or even multiple) file scripts with PHP.

## Features

The file is designed to be as lightweight and easy to work with as possible.

* Application Class (Common Logic)
* Simple Routing
* Bootstrap Styling (CDN)
* Single File App

## Develop

By default, Phingle has no 3rd party dependencies (although you could add some if needed) and you can directly start by
cloning this repository and copying the `phingle.php` file template, before you start to add your own custom
functionality.

```php
$app->route('default', function () {
$this->render('

Hello World

');
});
```

### Routing

Towards the bottom of the file, you will find a section where you can add your own custom callbacks and render HTML or
process form submissions. For a request to route to your custom callback, you just need to provide the `action`
parameter, either with a `GET` or `POST` request.

```php
$app->route('default', function () {
$content = <<

Default Page




Go To Second Page


HTML;

$this->render($content);
});

$app->route('second-page', function () {
$content = <<

Second Page




Go To Default Page


HTML;

$this->render($content);
});
```

### Form Submission

In the same way, you can include forms in your HTML mark up and add some server side request handling for them, by
utilizing the `action` parameter.

```php
$app->route('default', function () {
$content = <<

Default Page





Name




Submit



HTML;

$this->render($content);
});

$app->route('submission-callback', function () {
$name = $_POST['name'] ?? null;

if ( ! $name) {
die('No name POST parameter was provided.');
}

$content = <<

Hello {$name}!




Go To Default Page


HTML;

$this->render($content);
});
```

### Enable Authentication

You can easily protect the script with the built-in HTTP Basic Authentication.

At the top of your Phingle file, you will find the following section:

```php
const AUTH_USERNAME = 'administrator';

const AUTH_PASSWORD = ''; // Set a password to enable HTTP Basic Auth.
```

Change the username and set a password accordingly, so that the file requires the credentials before being executed on
the server.

## License

Code Licensed Under [GPL v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html) | Content Under [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/)

---

Website [alextselegidis.com](https://alextselegidis.com)  · 
GitHub [alextselegidis](https://github.com/alextselegidis)  · 
Twitter [@alextselegidis](https://twitter.com/AlexTselegidis)

###### More Projects On Github
###### ⇾ [Plainpad · Self Hosted Note Taking App](https://github.com/alextselegidis/plainpad)
###### ⇾ [Questionful · Web Questionnaires Made Easy](https://github.com/alextselegidis/questionful)
###### ⇾ [Integravy · Service Orchestration At Your Fingertips](https://github.com/alextselegidis/integravy)