Class TipyView
V in MVC. HTML template engine based on PHP output buffer and PHP itself
- Templates are located in app/views directory
- Templates are simple php files with .php extension.
- Templates have variables defined in controller's TipyOutput instance and don't
have access to application context except TipyView instance represented by $this (see note below)
// app/controllers/BlogController.php class BlogController extends TipyController { public function article() { $this->out('title', 'Hello'); $this->out('message', 'World!'); } }
// app/views/blog/article.php <!DOCTYPE html> <html> <head> <title><?= $title ></title> </head> <body> <p><?= $title.' '.$message ?></p> </body> </html>
Custom template names
You can explicitely render views with custom names
// app/controllers/BlogController.php class BlogController extends TipyController { public function article() { $this->out('title', 'Hello'); $this->out('message', 'World!'); $this->renderView('path/to/custom_template'); } }
Note about $this
$this is available inside template and gives access to TipyView instance which renders current template.
<ul>
<li>
<? $this->includeTemplate('item') ?>
</li>
</ul>
public
|
|
public
|
|
public
mixed
|
|
public
|
|
public
array
|
|
public
|
|
public
string
|
|
public
string
|
|
protected
|
#
includeTemplate( string $templateName )
Include template (child) to currently rendering template (parent). All parent template variables will be available to its children as they exist in one context. |
protected
|
#
applyTemplateStart( string $templateName )
Wrap another template (layout) around currently rendering template or even its part (child). |
protected
|
|
protected
|