323 Star 2K Fork 534

御宅男工作室 / YZNCMS

 / 详情

我没找到 获得文章总数的 方法,自己写了个,不知道这个是不是个普遍的需求

已完成
求助问题
创建于  
2019-05-23 23:03

在这个文件添加函数
application/cms/common.php

/**
 * 获得文章总数
 * @param $catid
 * @param $where
 *
 * @return float|string
 * @throws \think\db\exception\DataNotFoundException
 * @throws \think\db\exception\ModelNotFoundException
 * @throws \think\exception\DbException
 */
function articleCount($catid, $where)
{
    $_item = db('category')->where(['id' => $catid])->find();
    $_item = db('model')->where(['id' => $_item['modelid']])->find();

    return db($_item['tablename'])->where($where)->count();
}

控制器 $condition = paramdecode(input('condition')); 输出到膜版

            {php}
                $sql='';
                foreach($condition as $k => $v)
                {
                    $sql .= ' and ' . $k . ' = "' . $v . '" ';
                }
                $sql = ' status = 1 ' . $sql . ' ';
            {/php}
            {:articleCount($catid,$sql)}

这样就能获得文章数量了。还兼顾了检索。

评论 (2)

郭大鹏 创建了任务

这块用的不多
取模型id可以用

$modelid = getCategory($catid, 'modelid');

取表名可以用

$model_cache = cache("Model");
$model_table = ucwords($model_cache[$modelid]['tablename']);

谢谢。长知识了

郭大鹏 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
555541 ken678 admin 1578927533 127003 guodapeng 1578918754
PHP
1
https://gitee.com/ken678/YZNCMS.git
git@gitee.com:ken678/YZNCMS.git
ken678
YZNCMS
YZNCMS

搜索帮助

344bd9b3 5694891 D2dac590 5694891