美文网首页
TP5分页(5)

TP5分页(5)

作者: royluck | 来源:发表于2019-05-12 16:32 被阅读0次

model层
项目目录地址:application>common>model>Category.php

// 获取一级目录数据
public function getFirstCategorys(  $parentId = 0){
  $data = [
    'parent_id' =>  $parentId,
    'status' => ['neq', -1],
  ]
  
$order = [
  'id' => 'desc',
 ]

  $result = $this->where($data)
    ->order($order)
    ->paginate(2) // tp5分页!!! paginate()如果传空,默认为15条,可以在application>config.php里配置默认分页数据
    ->select();

  // 调试方法,打印输出的sql语句
  // echo $this->getLastSql() 
  return $result;
}

控制层
项目目录地址:application>admin>controller>Category.php

// 声明model全局变量
private $obj;
public function _initialize(){
  $this->obj = model("Category"); 
}
public function index(){
  $parentId =  input('get.parent_id',0,'intval');
  // 引用model
  $category = $this->obj->getFirstCategorys(  $parentId);
  // 调用模板
  return $this->fetch('',[
    'categorys' =>   $category
  ])
}

视图层

这里的status方法!!!

项目目录地址:application>admin>view>category>index.html

{volist name="categorys" id="vo"}
  <li>{$vo.name}</li>
  <!-->转换变量status,需要在common.php声明方法!!!!<-->
  <li>{$vo.status | status}</li> 
{/volist}

<!-->试图层分页<-->
<div class="cl pd-5 bk-gray mt-20">{$categorys->render()}</div> 

文件地址:
application>common.php

// 应用公共文件
function status($status){
  if($status == 1){
    $str = "<span class='label label-success radius'>正常</span>"
  }
  else if($status == 0){
    $str = "<span class='label label-success radius'>待审核</span>"
  }
else{
    $str = "<span class='label label-success radius'>删除</span>"
}
return $str;
}

相关文章

  • tp5 分页样式

    tp5 分页样式css

  • thinkphp使用layui 2.X的分页样式

    使用方法: 1. 在TP5配置文件中配置分页参数: //分页配置'paginate' => ['type' => ...

  • tp5 分页详解

    最常用的应该就是分页了,tp5已经将分页给封装好了,实在是方便! 分页主要在model中查询语句例使用pagina...

  • tp5分页 改动数据结构时报错问题

    以下是手册上,TP5分页的使用方法, 控制器中关键代码如下: 模板文件中分页输出代码如下: 上面的方法非常简单,但...

  • TP5分页(5)

    model层项目目录地址:application>common>model>Category.php 控制层项目目...

  • tp5 foreach分页类

    使用方法:在控制器中调用这个扩展类,new一个分页对象$p,并渲染到模板 注意:支持URL模式,模块/控制器/操作...

  • TP5分页

    其实分页自身的内容也不是很多。不过牵扯到样式的问题感觉挺烦。于是找到了分页类看了一下。把大体的结构说一下。如果有需...

  • TP5分页

    其实分页自身的内容也不是很多。不过牵扯到样式的问题感觉挺烦。于是找到了分页类看了一下。把大体的结构说一下。如果有需...

  • Tp5·paginate分页分析

    关于tp5的paginate方法,我查找了一些文档,没有去讲它的原理是什么样的,我们来分析一下这个方法会做什么 1...

  • Indirect modification of overloa

    thinkphp5.1报错这个解决方法 重新定义一个数组 原因:tp5使用分页类读取的数据不是纯数组的格式

网友评论

      本文标题:TP5分页(5)

      本文链接:https://www.haomeiwen.com/subject/hwmcaqtx.html