PHP code example of klan1 / k1.lib-dom

1. Go to this page and download the library: Download klan1/k1.lib-dom 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/ */

    

klan1 / k1.lib-dom example snippets


use \k1lib\html\DOM as DOM;

DOM::start('en');

$head = DOM::html()->head();
$body = DOM::html()->body();

$head->set_title("Simple example");

$p = new \k1lib\html\p("Helo world", "class-here", "id-here");

$p->append_to($body);

echo DOM::generate();

use \k1lib\html\DOM as DOM;

DOM::start();

DOM::html()->head()->set_title("Simple example");

DOM::html()->body()->append_p("Helo world", "class-here", "id-here");

echo DOM::generate();

$top_bar = new \k1lib\html\foundation\top_bar(DOM::html()->body()->header());

$top_bar->set_title(1, "APP TITLE");
$top_bar->set_title(2, " :: ");
$top_bar->set_title(3, "HOME");

$li = $top_bar->add_menu_item("#", "Sub menu 1");
$top_bar->add_menu_item("#", "Item 2");
$top_bar->add_menu_item("#", "Item 3");

$sub_menu = $top_bar->add_sub_menu($li);
$top_bar->add_menu_item("#", "Level 1", $sub_menu);
$top_bar->add_menu_item("#", "Level 2", $sub_menu);
$top_bar->add_menu_item("#", "Level 2", $sub_menu);

$top_bar->add_button("#", "Ingresar");
$top_bar->add_button("#", "Salir", "alert");

$data = array(
    0 => array(0 => 'Name', 1 => 'Last name', 'Full Name', 'Pic'),
    1 => array('Alejandro', 'Trujillo', "{{field:0}} {{field:1}}", 'https://66.media.tumblr.com/avatar_32dc0cfad91f_128.png'),
    2 => array('Camilo', 'Lopez', "{{field:0}} {{field:1}}", 'https://cdn1.iconfinder.com/data/icons/halloween-6/96/Zombie-128.png'),
);

$img = new \k1lib\html\img();
$img->set_attrib("alt", "Avatar of {{field:0}}");

$table_with_data = new \k1lib\html\foundation\table_from_data('foundation-table', 'table-1');
$table_with_data->set_data($data);
$table_with_data->insert_tag_on_field($img, [3], 'src');
$table_with_data->append_to($body->content());