PHP code example of initphp / views

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

    

initphp / views example snippets


$data = [
    'username'  => 'admin'
];

echo view('dashboard/dashboard', $data);

$data = [
    'username'  => 'admin'
];

echo view(['header', 'content', 'footer'], $data);

$data = new stdClass;
$data->username = 'admin';

echo view('dashboard/profile', $data);

use \InitPHP\Views\Facade\View;
use \InitPHP\Views\Adapters\PurePHPAdapter;

$viewAdapter = new PurePHPAdapter(__DIR__ . '/Views/');

View::via($viewAdapter);

use \InitPHP\Views\Facade\View;
use \InitPHP\Views\Adapters\BladeAdapter;

$viewAdapter = new BladeAdapter(__DIR__ . '/Views/', __DIR__ . '/Cache/');

View::via($viewAdapter);

View::directive('now', function ($format = null) {
    return ' echo '
            . ($format === null ? 'date("Y-m-d H:i:s")' : 'date(' . $format . ')')
            . ' 

use \InitPHP\Views\Facade\View;
use \InitPHP\Views\Adapters\TwigAdapter;

$viewAdapter = new TwigAdapter(__DIR__ . '/Views/', __DIR__ . '/Cache/');

View::via($viewAdapter);

$data = [
    'username'  => 'admin'
];

echo view('dashboard/dashboard.html', $data);