先上代码:

class Article extends Model
{
//获取全部文章
public function getArticleAll($id,$page)
{
$cate = new Cate();
$cate_id = $cate -> getchilrenid($id);
$cate_id = implode(',',$cate_id);
$ArticleAll = $this -> where('cateid','in',$cate_id) -> paginate($page);
return $ArticleAll;
} public function getArticleHot($id,$limit)
{
$cate = new Cate();
$cate_id = $cate -> getchilrenid($id);
$cate_id = implode(',',$cate_id);
$ArticleHot = $this -> where('cateid','in',$cate_id) -> order('click desc') -> limit($limit) -> select();
return $ArticleHot;
}
}

我在model类写了两个方法,注意,第一个是分页的,第二个是不分页的,但是我在调用的时候,第一个分页的方法也会影响第二个方法。导致两个方法都分页!

tp5--model的坑的更多相关文章

  1. tp5 model 中的查询范围(scope)

    查询范围scope在model中定义,在controller中使用 namespace app\index\model; use think\Model; class User extends Mod ...

  2. tp5 model 的数据自动完成

    auto属性自动完成包含新增和更新操作 namespace app\index\model; use think\Model; class User extends Model { protected ...

  3. tp5 model 中的类型转换

    类型转换使用 $type 定义 // 保存到数据库的数据会自动转换为相对应的格式class User extends Model { protected $type = [ 'status' => ...

  4. tp5 model 中的软删除

    model中需use traits\model\SoftDelete; // 数据表中需添加一个 delete_time 字段保存删除时间 namespace app\index\model; use ...

  5. TP5 model层 返回的对象转数组

    打开 database.php 增加或修改参数'resultset_type' => '\think\Collection',即可连贯操作 model('user')->select()- ...

  6. tp5 model controlle sql

    model::::use think\Db 引用db库类 用于数据库之类use think\Model 引用模板use think\Cookie 引用传值 $rs=Db::name(‘表名’)-> ...

  7. tensorflow 2.0 技巧 | 自定义tf.keras.Model的坑

    自定义tf.keras.Model需要注意的点 model.save() subclass Model 是不能直接save的,save成.h5,但是能够save_weights,或者save_form ...

  8. tp5 model 的时间戳

    单独在模型里面设置:(推荐) protected $autoWriteTimestamp = true; // int 型 protected $autoWriteTimestamp = 'datet ...

  9. ThinkPHP5的数据操作和Thinkphp3.2.3对比小结

    前言: 由于Thinkphp5和Thinkphp3.2.3的版本差距过大, 在记忆方面容易混淆. 故特意记录一下在数据操作上的对比的不同. Tp3.2.3 增:add(),addAll() 查:fin ...

  10. Spring Boot笔记一

    Spring Boot 入门 Spring Boot 简介 > 简化Spring应用开发的一个框架:> 整个Spring技术栈的一个大整合:> J2EE开发的一站式解决方案: 微服务 ...

随机推荐

  1. 详细解析kafka之 kafka消费者组与重平衡机制

    消费组组(Consumer group)可以说是kafka很有亮点的一个设计.传统的消息引擎处理模型主要有两种,队列模型,和发布-订阅模型. 队列模型:早期消息处理引擎就是按照队列模型设计的,所谓队列 ...

  2. C - Can you solve this equation? HDU - 2199(二分水题)

    Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...

  3. Reface.NPI 方法名称解析规则详解

    在上次的文章中简单介绍了 Reface.NPI 中的功能. 本期,将对这方法名称解析规则进行详细的解释和说明, 以便开发者可以完整的使用 Reface.NPI 中的各种功能. 基本规则 方法名称以 I ...

  4. eclipse报错:problems during content assist

    自动提示出错: 解决办法:Windows->preferences->java->editor->content assist->advanced 取消java prop ...

  5. 多线程之旅(Task 任务)

    一.Task(任务)和ThreadPool(线程池)不同       源码 1.线程(Thread)是创建并发工具的底层类,但是在前几篇文章中我们介绍了Thread的特点,和实例.可以很明显发现局限性 ...

  6. ELK数据批量导入

                                                                            数据批量导入 • 使用 _bulk 批量导入数据 – 批 ...

  7. Java第十五天,泛型

    一.定义 泛型是一种未知的数据类型,即当我们不知道该使用哪种数据类型的时候,可以使用泛型. 泛型的本质是为了  参数化 类型(在不创建新的类型的情况下,通过泛型指定的不同类型来控制形参具体限制的类型) ...

  8. Spring Cloud 系列之 Consul 注册中心(二)

    本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Consul 注册中心(一) 本篇文章讲解 Consul 集群环境的搭建. Consul 集群 上图是一个简单的 Co ...

  9. Java编程最差实践常见问题详细说明(1)转

    Java编程最差实践常见问题详细说明(1)转     原文地址:http://www.odi.ch/prog/design/newbies.php 每天在写Java程序, 其实里面有一些细节大家可能没 ...

  10. 数据结构和算法(Golang实现)(18)排序算法-前言

    排序算法 人类的发展中,我们学会了计数,比如知道小明今天打猎的兔子的数量是多少.另外一方面,我们也需要判断,今天哪个人打猎打得多,我们需要比较. 所以,排序这个很自然的需求就出来了.比如小明打了5只兔 ...