NewsModel::getOneyById PHP Method

getOneyById() public method

根据ID获取资料
public getOneyById ( integer $id, boolean $is_admin = false, $update_hits = false ) : array
$id integer
$is_admin boolean 是否是后台
return array
    public function getOneyById($id, $is_admin = false, $update_hits = false)
    {
        $map = array('news_id' => $id);
        if ($is_admin == false) {
            $map['state'] = array('GT', 0);
        }
        $v = $this->where($map)->find();
        if ($v) {
            $v['attachId'] = $v['image'];
            $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);
                }
            }
            $v['image'] = $thumb;
            //更新浏览量
            if ($is_admin === false && $update_hits == true) {
                $this->setInc('hits', array('news_id' => $id), 1);
            }
        }
        return $v;
    }

Usage Example

コード例 #1
0
 /**
  * 详细页
  *
  * @param int $id
  */
 public function detail()
 {
     $id = intval($_GET['id']);
     if (empty($id)) {
         $this->redirect(U('news/Index/index'));
     }
     $news = $this->_news->getOneyById($id, false, true);
     if (!$news) {
         $this->assign('jumpUrl', U('news/Index/index'));
         $this->error('该信息不存在或已被删除');
     }
     //获取用户信息
     if ($news['uid']) {
         $user = model('User')->getUserInfo($news['uid']);
         $this->assign('userinfo', $user);
     }
     $this->FormatSildeNews();
     //获取分类
     $type = model('CategoryTree')->setTable('news_category')->getCategoryById($news['type_id']);
     //SEO信息
     $this->setTitle($news['news_title'] . '_' . $this->tVar['_title']);
     if (isset($type['title'])) {
         $keywords = $news['news_title'] . ',' . $type['title'] . $this->tVar['_keywords'];
     } else {
         $keywords = $news['news_title'] . ',' . $this->tVar['_keywords'];
     }
     $this->setKeywords($keywords);
     $this->setDescription($news['news_title'] . ',' . msubstr(strip_tags($news['news_content']), 0, 200));
     $t = isset($type['id']) ? $type['id'] : 0;
     $this->assign('t', $t);
     $this->assign('type', $type);
     $this->assign('news', $news);
     $this->assign('current_url', U('news/Index/detail', array('id' => $id)));
     $this->display();
 }