- A lightweight view PHP library
composer require phpbook/view
<?php
/********************************************
*
* Declare Configurations
*
* ******************************************/
//Path root to views
\PHPBook\View\Configuration\View::setViewsPathRoot('main', 'path\to\views\base\dir');
\PHPBook\View\Configuration\View::setViewsPathRoot('anotherAlias', 'path\to\another\views\base\dir');
\PHPBook\View\Configuration\View::setDefaultPathRoot('main');
?>
My View Example One
<?php echo $title; ?>
<?php echo $jhon->name; ?>
<?php foreach($friends as $friend): ?>
<?php echo $friend->name; ?>
<?php endforeach; ?>
My View Example Two using another view inside
<?php
echo (new \PHPBook\View\View)
->setPathRoot('anotherAlias')
->setView('subpath/to/file/view')
->render();
?>
<?php
/*********************************************
*
* Rendering Views
*
* *******************************************/
$jhon = new StdClass;
$jhon->name = 'Jhon';
$jhon->age = 15;
$title = $jhon->name;
$ana = new StdClass;
$ana->name = 'Ana';
$ana->age = 15;
$paul = new StdClass;
$paul->name = 'Paul';
$paul->age = 16;
$friends = [$ana, $paul];
//data must be an array os values
$content = (new \PHPBook\View\View)
->setView('subpath/to/file/view/one')
->setData([
'title' => $title,
'jhon' => $jhon,
'friends' => $friends
])
->render();
echo $content;
?>