PHP code example of webfiori / ui

1. Go to this page and download the library: Download webfiori/ui library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webfiori / ui example snippets



WebFiori\Ui\HTMLDoc;

$doc = new HTMLDoc();
$doc->getHeadNode()->setPageTitle('My First Page');
$doc->setLanguage('en');

$body = $doc->getBody();
$body->addChild('h1')->text('Welcome to WebFiori UI!');
$body->addChild('p')->text('Building HTML has never been easier.');

echo $doc;

use WebFiori\Ui\HTMLDoc;

$doc = new HTMLDoc();
$doc->getHeadNode()->setPageTitle('My Application');
$doc->setLanguage('en');

$head = $doc->getHeadNode();
$head->addMeta('description', 'A powerful web application');
$head->addCSS('styles/main.css');
$head->addJs('scripts/app.js');

$body = $doc->getBody();
$body->addChild('header')->addChild('h1')->text('My Application');
$body->addChild('main')->addChild('p')->text('Main content here.');
$body->addChild('footer')->addChild('p')->text('© 2024 My App');

echo $doc;

use WebFiori\Ui\HTMLNode;

// Create elements with attributes
$div = new HTMLNode('div', ['id' => 'main', 'class' => 'container']);
$div->addChild('p')->text('Hello World');

// Method chaining
$div->setAttribute('data-role', 'content')
    ->setStyle(['padding' => '1rem']);

// Iterate children
foreach ($div as $child) {
    echo $child->getNodeName();
}

$form = $body->form(['method' => 'post', 'action' => '/login']);

$form->label('Username:');
$form->br();
$form->input('text', ['name' => 'username', 'bmit', ['value' => 'Login']);

use WebFiori\Ui\HTMLTable;

$table = new HTMLTable(3, 4);
$table->getCell(0, 0)->text('Name');
$table->getCell(0, 1)->text('Email');

$card = HTMLNode::fromFileAsNode('template.html', [
    'title' => 'My Card',
    'content' => 'Card body text'
]);

// template.php
<ul>
 foreach ($items as $item): 

$list = HTMLNode::fromFileAsNode('template.php', [
    'items' => ['Apple', 'Banana', 'Cherry']
]);
bash
cd tests
php ../vendor/bin/phpunit