Blogger Information
Blog 55
fans 0
comment 1
visits 42097
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用foreach和volist标签分别实现模板数据的分页显示-2018年6月1日11点30分
旺小舞的博客
Original
889 people have browsed it

列图:

1.png

需要的准备文档  app\index\controller\Staffa.php, app\index\model\Staffa.php,app\index\view\staffa\demo2.html

app\index\model\Staffa.php 

<?php
namespace app\index\model;
use think\Model;

class Staffa extends Model
{
	protected $table = 'staff';

	protected $pk = 'staff_id';
}

app\index\controller\Staffa.php

<?php
namespace app\index\controller;
use think\Controller;
//use think\facade\Request;
use app\index\model\Staffa as StaffaModel;

class Staffa extends Controller
{
      public function demo2()
	{
		//分页配置
		$config = [
			'type' => 'bootstrap',//驱动类型
			'var_page' => 'page' //分页变量
		];

		//每页显示的数量
		$num = 5;
		//是否简单分页?上/下一页
		$simple =false;

		//用模型来获取所有的分页数据:think\Paginate
		$paginate = StaffaModel::paginate($num,$simple,$config);
		// halt($paginate); //返回的是对象
		//渲染分页的HTML代码,返回分页变量
		$page = $paginate->render();
		// halt($page); //返回的是html代码
		
		//将分页的数据赋值给模板
		$this->view->assign('staffs',$paginate);
		//降分页变量赋值给模板
		$this->view->assign('page',$page);
		//渲染模板
		return $this->view->fetch();
	}

}

app\index\view\staffa\demo2.html

<!-- <link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css"> -->
{load  href="/static/bootstrap/css/bootstrap.css"}
<div class="container">
	<div class="row">
		<h3 class="text-center">员工信息登记表</h3>
		<div class="col-md-8 col-md-offset-2">
			<table class="table table-bordered table-hover text-center">
				<tr class="info">
					<td>ID</td>
					<td>姓名</td>
					<td>性别</td>
					<td>年龄</td>
					<td>工资</td>
				</tr>

			{volist name="staffs" id="staff" }
					<tr>
						<td>{$staff.staff_id}</td>
						<td>{$staff.name}</td>
						<td>
							{//$staff.sex}
							{//性别必须是0或1,才是合法数据  枚举}
							{in name="staff.sex" value="0,1"}
								{if $staff.sex == 0}
								男
								{else /}
								女
								{/if}
							{/in}
						</td>
						<td>
							{$staff.age}
							{//between标签 连续的数据}
							{between name="staff.age" value="10,30"}
								很年轻嘛
							{/between}

							{between name="staff.age" value="31,50"}
								人到中年
							{/between}

							{between name="staff.age" value="51,100"}
								快退休了
							{/between}
						</td>
						<td>{$staff.salary}</td>
					</tr>				
			{/volist}		
			</table>
			<div class="text-center">{$page|raw}</div>
		</div>
	</div>
</div>

{load  href="/static/jquery/jquery.js"}
{load  href="/static/bootstrap/js/bootstrap.js"}



Correction status:Uncorrected

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