Merge(聚合模型)如何使用分页查询.

浏览:1131 发布日期:2016/06/28 分类:求助交流 关键字: 聚合模型
<?php
namespace app\center\model;

use think\model\Merge;
class News extends Merge
{
    protected $connection = [
        // 数据库类型
        'type'     => 'mysql',
        // 服务器地址
        'hostname' => '127.0.0.1',
        // 数据库名
        'database' => 'walk',
        // 数据库用户名
        'username' => 'root',
        // 数据库密码
        'password' => '',
        // 数据库编码默认采用utf8
        'charset'  => 'utf8',
        // 数据库表前缀
        'prefix'   => 'think_',
        // 数据库调试模式
        'debug'    => false,
    ];
    // 设置主表名
    protected $table = 'think_user';
    // 定义关联模型列表
    protected static $relationModel = [
        // 给关联模型设置数据表
        'Profile' => 'think_user_profile',
    ];
    // 定义关联外键
    protected $fk        = 'user_id';
    protected $mapFields = [
        // 为混淆字段定义映射
        'id'         => 'News.id',
        'profile_id' => 'Profile.id',
    ];
    public static function paginate($listRows = null, $data = '', $with = [], $cache = false)
    {
        $query = self::parseQuery($data, $with, $cache);
        $query = self::attachQuery($query);
        return $query->paginate($listRows);
    }
}
/*
数据表结构:http://www.kancloud.cn/manual/thinkphp5/144721
使用时:
$rows = \app\center\model\News::paginate(2,function ($query) {
$query->where('name', "1")->order('news.id', 'desc');
});
var_dump($rows);exit;
 */
谢谢.分享一下代码.
最佳答案
评论( 相关
后面还有条评论,点击查看>>