-
Notifications
You must be signed in to change notification settings - Fork 4
View
やかみそら edited this page May 5, 2017
·
7 revisions
The view engine uses the native PHP, not using the template language.
Use View::assign()
to assign variable to view, View::display()
to render view.
The assign
method can be passed two arguments, the first argument is the template variable name, and the second argument is the template variable value.
The display
method can accept 1 or 0 arguments.
Example:
class Index extends Controller {
public function index() {
$this->view->assign('var', 'hello Kotori');
$this->view->display(); // Use views/Index/index.html for template
}
public function test() {
$this->view->display('Nico/test'); // Use views/Nico/test.html for template
}
}
Template inheritance function. The need
method can be passed two arguments, the first argument is the template variable name, just similar to the display
method, and the second argument is data, usually not necessary.
For example, there is a public header file located in View/Public/header.html
:
<head>
<title><?php echo $title;?></title>
</head>
We need to introduce the header template in the main page:
<html>
<?php $this->need('Public/header', $data); ?>
<body>
...