Giter Club home page Giter Club logo

phingle's Introduction


Phingle
Phingle


Single File App Template

AboutStructureDevelopLicense

screenshot

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.

$app->route('default', function () {
	$this->render('<h1>Hello World</h1>');
});

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.

$app->route('default', function () {
	$content = <<<HTML
        <div>
            <h1>Default Page</h1>
            
            <a href="?action=second-page" class="btn btn-primary">
                Go To Second Page
            </a>
        </div>
HTML;

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

$app->route('second-page', function () {
	$content = <<<HTML
        <div>
            <h1>Second Page</h1>
            
            <a href="?action=default" class="btn btn-primary">
                Go To Default Page
            </a>
        </div>
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.

$app->route('default', function () {
	$content = <<<HTML
        <div>
            <h1>Default Page</h1>
            
            <form action="?action=submission-callback" method="post">
                <div class="mb-3">
                    <label for="name" class="form-label">Name</label>
                    <input type="text" name="name" id="name" class="form-control" required />
                </div>
                
                <button type="submit" class="btn btn-primary">
                    Submit    
                </button>
            </form>
        </div>
HTML;

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

$app->route('submission-callback', function () {
    $name = $_POST['name'] ?? null;
    
    if ( ! $name) {
        die('No name POST parameter was provided.'); 
    }

	$content = <<<HTML
        <div>
            <h1>Hello {$name}!</h1>
            
            <a href="?action=default" class="btn btn-primary">
                Go To Default Page
            </a>
        </div>
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:

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 | Content Under CC BY 3.0


Website alextselegidis.com  ·  GitHub alextselegidis  ·  Twitter @alextselegidis

More Projects On Github

phingle's People

Contributors

alextselegidis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.