运行效果图:
demo1
demo2:
demo3:
demo4:
代码:
实例
<?php namespace app\index\controller; use think\facade\View; use think\Controller; class Test extends Controller { public function test() { return '<h3>欢迎来学习<span style="color:red">ThinkPHP5.1</span>框架开发</h3>'; } //模板赋值 public function demo1() { $this->view->age = 28; return $this->view->fetch(); } //模板替换和过滤 public function demo2() { $this->view->assign('age','25'); $filter = function($content) { return str_replace('25', '29', $content); }; return $this->filter($filter)->fetch(); } //模板布局 public function demo3() { return $this->view->engine->layout('layout','{__TEXT__}')->fetch('test/demo3'); } //模板继承 public function demo4() { return $this->view->fetch(); } }
运行实例 »
点击 "运行实例" 按钮查看在线实例