PHPFront
PHPFront will help you read/write content on HTML templates from within your PHP application, read/write on attributes, traverse up/down the full document, manipulate - create, repeat, import, relocate, replace, remove - elements dynamically, produce a clean HTML output that represents your entire application. This is server-side rendering., (*1)
It implements the JQuery API with its powerful CSS3 selectors and chainable methods. It is well-tested and greatly optimized for use in websites and other PHP-based applications; built with love to bring all the ease and fun to your code, and a whole lot of new possibilities!, (*2)
Installation
Requirement
PHPFront requires a web server running PHP 5.3 or greater., (*3)
Installation
There are two options:, (*4)
With Composer
composer
composer require ox-harris/phpfront, (*5)
From Github
Download from Github: github.com/ox-harris/phpfront/releases, (*6)
Extract the PHPFront zip file and youâll discover the most important folder for use named âlibâ.
This folder contains the core working files. This folder and its content are things you SHOULD NOT edit., (*7)
Move the PHPFront folder to the frontend directory of your project or anywhere from the root directory of your project â depending on your applicationâs directory structure. Just make sure your applicationâs autoloader can pick up the PHPFront class when called â thatâs if your project is bundled with an autoloader. Or simply note down the path to where you decide to put the PHPFront files so you can manually include this path during setup., (*8)
Test
To see if PHPFront is available for use, use PHPFront::info(). This should show a few lines of info.
If you just want to test PHPFront or if your project is nothing more than basic, here is a test-case setup in numbered steps.
* Create a new php file named âapp.phpâ â just the name for this example.
* Copy the PHPFront folder to the same directory as the app.php file.
* Create a plain HTML page named âtemplate.htmlâ- one that contains no php tags â and put the file in this same directory., (*9)
Then in your app.php:
-
Include the PHPFront class., (*10)
Include âPHPFront/lib/PHPFront.phpâ;
// If you stored the PHPFront folder in a different location, your include path would change.
// Where âpath-to-PHPFrontâ is your actual path to where you stored PHPFront
Include âpath-to-PHPFront/PHPFront/lib/PHPFront.phpâ;
-
PHPFront is now available to our app.php script, so we instantiate it:, (*11)
$PHPFront = new PHPFront;
-
Now, we hand PHPFront the template to use - our template.html page, (*12)
$PHPFront->setTemplate(âtemplate.htmlâ);
// If your stored template.html in a different location, your path would change.
// Where âpath-to-template is your actual path to where you stored template.html
$PHPFront->setTemplate(âpath-to-template/template.htmlâ);
-
Now we can start reading and writing content on respective elements in the template with CSS3 selectors, (*13)
// For document title (title)
$PHPFront->find(âtitleâ)->html(âThis is document titleâ);
// For page heading 1 (h1)
$PHPFront->find(âh1â)->html(âHello World!â);
// For page paragraph (p)
$PHPFront->find(âpâ)->html(âHere is my first PHPFront projectâ)->addClass('rounded-corners')->css('color', 'gray');
// Load a HTML fragment into a DIV and manipulate its content
$PHPFront->find('#container')->load(__DIR__.'/templates/table.html')->find('tr:even')->css('background-color', 'whitesmoke')
->parents('table')->attr('id', 'employee-table')->append('<tr><td>342</td><td>John Doe</td></tr>');
-
Finally, we render our page using PHPFrontâs render() function, (*14)
$PHPFront->render();
And thatâs it! Preview your app.php in a browser and experience the PHPFront's simplicity and neatness first time on your project!, (*15)
Documentation
https://ox-harris.github.io/phpfront/documentation/ (FOR phpFront v1.0.0), (*16)
Feedback
All bugs, feature requests, pull requests, feedback, etc., are welcome. Create an issue., (*17)
Follow Up
https://www.twitter.com/PHPFront., (*18)
Visit
http://www.facebook.com/PeeHPFront, (*19)
Authors
Oxford Harrison ox_harris@yahoo.com, (*20)
License
GPL-3.0 - See LICENSE, (*21)