- This is an open-source library, and contributions are welcome.
- If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the project repository.
- PHP version 8.0 or newer is required
- You can just download the code from repo and use or download using composer.
- If you don't have composer, install composer first.
- create file
composer.jsonat your project root directory. - Add this to
composer.json
{
"require": {
"naingaunglwin-dev/view": "^1.0"
}
}- Run the following command in your terminal from the project's root directory:
composer install- Or just run
composer require naingaunglwin-dev/viewin terminal.
- In your php file,
<?php
require_once "vendor/autoload.php";
use NAL\View\View;
$view = new View(__DIR__ . '/views');
// You can pass view file without extension if it is php file
$view->render('index', ['status' => 'success']);
// You can also render other file,
// You can retrieve the view without rendering,
$indexView = $view->render('index.html', [], true);
// You can also render multi views
$view->render(['index.html, test']);- If you don't define your view path, View class will automatically set the view path to your project root level
-
create
one.phpandtwo.php -
one.php
<?php //one.php
echo 'this is one.php';
$this->yield('content');- two.php
<?php //two.php
$this->extends('one'); // view file name that need to extend
$this->section('content'); // Section start with `content` name
echo '<br>This is section content from two.php';
$this->end('content'); // End the section `content`- index.php
<?php
require_once "vendor/autoload.php";
use NAL\View\View;
$view = new View(__DIR__ . '/views');
$view->render('two');- Output will be
this is one.php
This is section content from two.php<?php
$view = new \NAL\View\View('path', MyCustomEngine::class);
$view->render('template'); // MyCustomEngine`s render method will be used in this process if exists