dev-master
9999999-dev https://github.com/cesar-v/viewsSimple View Renderer
MIT
by Cesar Vega
view views
Simple View Renderer
A simple view renderer - will read a .phtml file from the directory passed to the views.dir option, bind variables to it, and return the content as a string., (*1)
NO HEAVY TEMPLATE ENGINE! - PHP does templating on it's own, remember?, (*2)
The following options are avaliable during object construction:, (*3)
Option | Description | Required |
---|---|---|
views.dir | Root path of your views directory. | Yes |
Consider the following directory structure:, (*4)
app/ โโโ index.php โโโ vendor โย ย โโโ autoload.php โโโ views โโโ Hello.phtml
Hello.phtml contains the following:, (*5)
<!doctype html> <html> <head> <title>Hello</title> </head> <body> <p>Hello <?= $name ?></p> </body> </html>
This is how we render our view from index.php:, (*6)
<?php require 'vendor/autoload.php'; $views = new \CesarV\Views\View(array( 'views.dir' => __DIR__ . '/views' )); echo $views->render('hello', array('name' => 'Cesar'));
Notice that array('name' => 'Cesar') became $name in Hello.phtml?, (*7)
Simple View Renderer
MIT
view views