Mini view is minimal template rendering library
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
nbproject
src
tests
.gitattributes
.gitignore
.scrunitizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTORS.md
INSTALL.md
LICENSE-AGPL.mkd
LICENSE-COMMERCIAL-SAAS.mkd
LICENSE-COMMERCIAL-WEBSITE.mkd
README.mkd
UPGRADE.md
codeception.yml
composer.json
composer.lock
make-unit
run-test
run-tests
run-tests-coverage
run-travis

README.mkd

Maslosoft Miniview

Mini view is minimal template rendering library based on Yii controller renderer

Latest Stable Version License [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Maslosoft/Miniview/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Miniview/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Maslosoft/Miniview/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Miniview/?branch=master)

Quick Install

composer require maslosoft/miniview

Usage

This is some example widget using MiniView:

namespace Company\SomeNamespace;

use Maslosoft\MiniView\MiniView;

class MyWidget
{

	/**
	 * View renderer
	 * @var MiniView
	 */
	public $view = null;
	
	/**
	 * @var string
	 */
	public $version = '';

	public function __construct()
	{
		$this->view = new MiniView($this);
		$this->version = $this->view->getVersion();
	}

	public function show()
	{
		return $this->view->render('myView', ['user' => 'Joe'], true);
	}

	public function greet($name)
	{
		return "Nice to meet you $name!" . PHP_EOL;
	}
}

In view file, all widget public properties as well as methods are available using $this. View file is located in folder views located in same folder as widget class.

Example view file:

Hello <?= $user ?>!
<?= $this->greet($user);?>
The version is <?= $this->version;?>

Calling show() will return rendered view file located in classFolder/views/myView.php with variable $user with value Joe.

use Company\SomeNamespace\MyWidget;

require __DIR__ . '/../src/Miniview.php';
require __DIR__ . '/MyWidget.phps';

$widget = new MyWidget;

echo $widget->show();

Run example

Go to examples folder and type php run.php