Blogger Information
Blog 64
fans 2
comment 1
visits 47016
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模板赋值、模板内容过滤、替换技术、模板动态布局、模板继承技术——2018年5月30日
Y的博客
Original
856 people have browsed it

运行效果图:

demo1

1.jpg

demo2:

360截图16171113376357.jpg

demo3:

3.jpg

demo4:

4.jpg

代码:

实例

<?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();
    }

}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post