PHP Classes

File: example_4_adding_child_by_parent_id

Recommend this page to a friend!
  Classes of Tony Frezza   HTML Generate   example_4_adding_child_by_parent_id   Download  
File: example_4_adding_child_by_parent_id
Role: Example script
Content type: text/plain
Description: Example 4 Adding Child By Parent id
Class: HTML Generate
Generate HTML from arrays
Author: By
Last change: edit class name to UML template
Date: 7 years ago
Size: 2,149 bytes
 

Contents

Class file image Download
<?php

/**
 * @author Tony Frezza
 * @copyright 2017
 */

   
include('html.php');
   
   
   
$html = new Html;
   
   
   
/**
        En:
            Once the id tag is not entered, the class will automatically generate an id.
            Every time a node is added, the add method returns the id, whether it is entered from the id tag or not.
            It is possible to add a child node to a parent node, informing the id of the parent node
       
        Pt-BR:
            Uma vez que não seja informada a tag id, a classe se encarrega de gerar uma id automaticamente.
            Toda vez que um nó é adicionado, o metodo add retorna a id, seja ela informada a partir da tag id ou não.
            É possível adicionar um nó filho a um nó pai, informando a id do nó pai
     */
    
   
   
   
$idNodeParent = $html->add(
        array(
           
'tag' => 'ul'
       
)
    );
   
   
$html->add(
        array(
           
'tag' => 'li',
           
'text' => 'foo',
           
'parent_id' => $idNodeParent,
        )
    );
   
   
$html->add(
        array(
           
'tag' => 'li',
           
'text' => 'bar',
           
'parent_id' => $idNodeParent,
        )
    );
   
    echo
$html->getHtml();
   
   
$html->resetHtml();
   
   
   
$idContainer = $html->add(
        array(
           
'tag' => 'div',
           
'style' => 'width: 100%; border: solid; text-align: center;',
        )
    );
   
   
$html->add(
        array(
           
'tag' => 'div',
           
'style' => 'width:100%; height: 20px; background: red;',
           
'text' => 'Child DIV node with style attribute',
           
'parent_id' => $idContainer,
        )
    );
   
   
$html->add(
        array(
           
'tag' => 'div',
           
'style' => 'width:100%; height: 30px; background: blue;',
           
'text' => 'Child DIV node with style attribute',
           
'parent_id' => $idContainer,
        )
    );
   
    echo
$html->getHtml();
?>