NewsModel::getList PHP Method

getList() public method

前台列表获取
public getList ( $limit = 20, $type, $keywords = '', $order = '', $findPage = true )
    public function getList($limit = 20, $type = 0, $keywords = '', $order = '', $findPage = true)
    {
        $map = array();
        $map['state'] = array('GT', 0);
        if ($keywords) {
            $map['news_title'] = array('like', '%' . $keywords . '%');
        }
        if ($order == '') {
            $order = 'is_top desc,news_id desc';
        }
        if ($type) {
            //获取子分类
            $childs = $this->getChildTids($type);
            if ($childs) {
                $childs[] = $type;
                $map['type_id'] = array('in', $childs);
            } else {
                $map['type_id'] = $type;
            }
        }
        $this->where($map)->order($order);
        if ($findPage) {
            $list = $this->findPage($limit);
            $data = $list['data'];
        } else {
            $data = $this->findAll(array('limit' => $limit));
        }
        foreach ($data as $k => $v) {
            $thumb = APPS_URL . '/' . APP_NAME . '/_static/nopic.jpg';
            if ($v['image']) {
                $attach = model('Attach')->getAttachById($v['image']);
                if ($attach) {
                    $thumb = getImageUrl($attach['save_path'] . $attach['save_name'], 100, 100);
                }
            }
            $data[$k]['image'] = $thumb;
            $data[$k]['title_intro'] = msubstr($v['news_title'], 0, 30);
            $data[$k]['content_intro'] = msubstr(strip_tags($v['news_content']), 0, 100);
            //获取评论数量
            $data[$k]['comment_count'] = model('Comment')->where(array('app' => 'news', 'table' => 'news', 'is_del' => 0, 'row_id' => $v['news_id']))->count();
        }
        if ($findPage) {
            $list['data'] = $data;
            return $list;
        } else {
            return $data;
        }
    }

Usage Example

Example #1
0
 /**
  * 初始化测栏数据
  *
  */
 private function FormatSildeNews($type = 0)
 {
     //最新
     $this->assign('silde_new_news', $this->_news->getList(10, $type, '', 'news_id desc', false));
     //热门
     $this->assign('silde_hot_news', $this->_news->getList(10, $type, '', 'hits desc', false));
 }