maslosoft/miniview

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

1.1.1 2017-02-16 07:45 UTC

README

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)

68747470733a2f2f7472617669732d63692e6f72672f4d61736c6f736f66742f4d696e69766965772e7376673f6272616e63683d6d6173746572

687474703a2f2f6868766d2e683463632e64652f62616467652f6d61736c6f736f66742f6d696e69766965772e7376673f7374796c653d666c6174

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