ThinkPHP模板之二
Posted aguncn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ThinkPHP模板之二相关的知识,希望对你有一定的参考价值。
模板布局及变量比较,循环。
controller
<?php /** * Created by PhpStorm. * User: Sahara * Date: 2019/6/23 * Time: 22:33 */ namespace Home\\Controller; use Think\\Controller; class DemoController extends Controller public function index() $projects = array( array( ‘name‘ => ‘PHP‘, ‘members‘ => array( array( ‘id‘ => 1, ‘name‘ => ‘Jim‘ ), array( ‘id‘ => 2, ‘name‘ => ‘Tome‘ ) ) ), array( ‘name‘ => ‘Java‘, ‘members‘ => array( array( ‘id‘ => 3, ‘name‘ => ‘White‘ ), array( ‘id‘ => 4, ‘name‘ => ‘Black‘ ) ) ), ); $age = 18; $this->assign(‘projects‘, $projects); $this->assign(‘age‘, $age); $this->display();
layout
<include file="Demo:header" /> <div class="content" > __CONTENT__ </div> <include file="Demo:footer" />
index
<layout name="Demo/layout" /> <h2>volist</h2> <ul> <volist name="projects" key="k" id="project"> <li>$k - $project.name</li> </volist> </ul> <h2>foreach</h2> <ul> <foreach name="projects" item="project" key="k" > <li>$k - $project.name</li> </foreach> </ul> <h2>for</h2> <ul> <for start="0" end="count($projects)" name="index" > <li>$index - $projects[$index][‘name‘]</li> </for> </ul> <h2>switch</h2> <div> <switch name="age"> <case value="18">18 year</case> <default /> not 18 year </switch> </div>
效果
以上是关于ThinkPHP模板之二的主要内容,如果未能解决你的问题,请参考以下文章