naingaunglwin-dev / view
Simple PHP View Library
1.0.0
2024-05-03 14:03 UTC
Requires
- php: ^8.0
This package is auto-updated.
Last update: 2024-09-17 13:52:40 UTC
README
Simple PHP View Library
Contributing
- 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.
Requirement
- PHP version 8.0 or newer is required
Installation & Setup
- You can just download the code from repo and use or download using composer.
Download Using Composer
- If you don't have composer, install composer first.
- create file
composer.json
at 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/view
in terminal.
Usage
- 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']);
Section Usage
-
create
one.php
andtwo.php
-
one.php
<?php //one.php echo 'this is one.php'; $this->displaySection('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->endSection('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