联系官方销售客服
1835022288
028-61286886
点击一个栏目进去后显示当前栏目第一篇文章的内容的设计方法
模块目录:news
修改文件:dayrui/App/News/Controllers/Category.php
<?php namespace Phpcmf\Controllers; /** * 二次开发时可以修改本文件,不影响升级覆盖 */ class Category extends \Phpcmf\Home\Module { public function index() { $page = max(1, (int)\Phpcmf\Service::L('Input')->get('page')); // 初始化模块 $this->_module_init(); $catid = (int)\Phpcmf\Service::L('Input')->get('id'); $catdir = dr_safe_replace(\Phpcmf\Service::L('Input')->get('dir')); if ($catid) { $category = $this->module['category'][$catid]; if (!$category) { $this->goto_404_page(dr_lang('模块【%s】栏目(%s)不存在', $this->module['dirname'], $catid)); return; } } elseif ($catdir) { $catid = intval($this->module['category_dir'][$catdir]); $category = $this->module['category'][$catid]; if (!$category) { // 无法通过目录找到栏目时,尝试多及目录 foreach ($this->module['category'] as $t) { if ($t['setting']['urlrule']) { $rule = \Phpcmf\Service::L('cache')->get('urlrule', $t['setting']['urlrule']); $rule['value']['catjoin'] = '/'; if ($rule['value']['catjoin'] && strpos($catdir, $rule['value']['catjoin'])) { $catdir = trim(strchr($catdir, $rule['value']['catjoin']), $rule['value']['catjoin']); if (isset($this->module['category_dir'][$catdir])) { $catid = $this->module['category_dir'][$catdir]; $category = $this->module['category'][$catid]; break; } } } } // 返回无法找到栏目 if (!$category) { $this->goto_404_page(dr_lang('模块【%s】栏目(%s)不存在', $this->module['dirname'], $catdir)); return; } } } else { $this->goto_404_page(dr_lang('模块【%s】栏目不存在', $this->module['dirname'])); return; } $row = \Phpcmf\Service::M()->table(SITE_ID.'_'.MOD_DIR)->where_in('catid', $category['catids'])->order_by('updatetime desc')->getRow(); if (!$row) { $this->goto_404_page(dr_lang('模块【%s】栏目(%s)没有内容', $this->module['dirname'], $catid)); return; } $this->_Show($row['id'], [], $page); } }
查询栏目的第一条内容,按时间排序的
来学习一下方法