PHP code example of phpbook / view

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

    

phpbook / view example snippets




/********************************************
 * 
 *  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

	 echo $title; 


	My View Example Two using another view inside

	  
		echo (new \PHPBook\View\View)
			->setPathRoot('anotherAlias')
			->setView('subpath/to/file/view')
			->render();
	

 

/*********************************************
 * 
 *  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;