PHP code example of makinacorpus / php-layout

1. Go to this page and download the library: Download makinacorpus/php-layout 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/ */

    

makinacorpus / php-layout example snippets


// Create types
$aType = new ItemAType();

// Place a top level container and build layout (no items)
$topLevel = new TopLevelContainer('top-level');
$c1 = new HorizontalContainer('C1');
$topLevel->append($c1);
$c11 = $c1->appendColumn('C11');
$c12 = $c1->appendColumn('C12');
$c2 = new HorizontalContainer('C2');
$c12->append($c2);
$c21 = $c2->appendColumn('C21');
$c22 = $c2->appendColumn('C22');

// Now place all items
$a1  = $aType->create(1);
$a2  = $aType->create(2);
$a3  = $aType->create(3);
$a4  = $aType->create(4);
$a5  = $aType->create(5);
$a6  = $aType->create(6);
$a7  = $aType->create(7);

$c11->append($a1);
$c11->append($a4);

$c21->append($a2);
$c21->append($a5);

$c22->append($a3);

$topLevel->append($a6);
$topLevel->append($a7);

// This is the class you would change in order to integrate more deeply with
// your own theme and templating engine, or if you do not use bootstrap but
// another grid layout.
$gridRenderer = new BootstrapGridRenderer();

$itemTypeRegistry = new ItemTypeRegistry();
$itemTypeRegistry->registerType($aType);

$renderer = new Renderer($itemTypeRegistry, $gridRenderer);
$string = $renderer->render($topLevel);