联系官方销售客服

1835022288

028-61286886

求助 版主:官方研发技术组
重写Content的_call_show 怎么设置上一页和下一页的条件
类型:迅睿CMS 更新时间:2022-04-17 21:41:34

发现4.5.3开始Content类的_call_show在上一页下一页的上面了


之前我是通过模块中重写Content的_call_show 设置了上一页下一页的条件小于当前时间的显示

所以现在用不了

想问下是否会调整回来呢?

如果不调整回来 是否还有其他方法处理呢?

回帖
  • #1楼    迅睿框架创始人
    2022-02-10 21:01:31
    Google Pixel 手机 0
    需要把你的代码发出来看看
  • 亿友
    #2楼    亿友
    2022-02-10 21:04:41
    Chrome 0
    我的模块重写代码
    <?php
    namespace Phpcmf\Model\News;
    
    // 模块内容模型类
    
    class Content extends \Phpcmf\Model\Content {
    
       
        
        // 格式化处理内容
        public function _call_show($data) {
            // 上一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id<', (int)$data['id'])->where('inputtime<=', time())->orderBy('id desc');
            $data['prev_page'] = $builder->limit(1)->get()->getRowArray();
    
    
            // 下一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id>', (int)$data['id'])->where('inputtime<=', time())->orderBy('id asc');
    		var_dumo
            $data['next_page'] = $builder->limit(1)->get()->getRowArray();
    
            return $data;
        }
    }
    4.5.4以上的Content类的_call_show
        // 内容页面的字段格式化处理
        protected function _Show_Data($data, $page) {
    
            // 处理关键字标签
            $data['tag'] = $data['keywords'] = trim($data['keywords']);
            $data['kws'] = [];
            $data['tags'] = [];
            if ($data['keywords']) {
                $tag = explode(',', $data['keywords']);
                $obj = false;
                if (dr_is_app('tag')) {
                    // 是否安装tag
                    $obj = \Phpcmf\Service::M('tag', 'tag');
                    if (!method_exists($obj, 'get_tag_url')) {
                        $obj = false;
                    }
                }
                foreach ($tag as $t) {
                    $t = trim($t);
                    if ($t) {
                        // 读缓存
                        if ($obj) {
                            $url = $obj->get_tag_url($t);
                            if ($url) {
                                $data['tags'][$t] = $url;
                            }
                        }
                        $data['kws'][$t] = \Phpcmf\Service::L('router')->search_url([], 'keyword', $t, MOD_DIR);
                    }
                }
            }
    
            // 格式化输出自定义字段
            $fields = $this->module['category_data_field'] ? array_merge($this->module['field'], $this->module['category_data_field']) : $this->module['field'];
            $fields['inputtime'] = ['fieldtype' => 'Date'];
            $fields['updatetime'] = ['fieldtype' => 'Date'];
    
            // 格式化字段
            $data = \Phpcmf\Service::L('Field')->app($this->module['dirname'])->format_value($fields, $data, $page);
    
            // 挂钩点 内容读取之后
            $rt2 = \Phpcmf\Hooks::trigger_callback('module_show_data', $data);
            if ($rt2 && isset($rt2['code']) && $rt2['code']) {
                $data = $rt2['data'];
            }
    
            // 模块的回调处理
            $data = $this->content_model->_call_show($data);
    
            if ($this->is_prev_next_page) {
                // 关闭插件嵌入
                $is_fstatus = dr_is_app('fstatus') && isset($this->module['field']['fstatus']) && $this->module['field']['fstatus']['ismain'] ? 1 : 0;
    
                // 上一篇文章
                $builder = \Phpcmf\Service::M()->db->table($this->content_model->mytable);
                $builder->where('catid', (int)$data['catid']);//->where('status', 9)
                $is_fstatus && $builder->where('fstatus', 1);
                $builder->where('id<', (int)$data['id'])->orderBy('id desc');
                $data['prev_page'] = $builder->limit(1)->get()->getRowArray();
                if (isset($data['prev_page']['url']) && $data['prev_page']['url']) {
                    $data['prev_page']['url'] = dr_url_prefix($data['prev_page']['url'], $this->module['dirname'], SITE_ID, $this->is_mobile);
                }
    
                // 下一篇文章
                $builder = \Phpcmf\Service::M()->db->table($this->content_model->mytable);
                $builder->where('catid', (int)$data['catid']);//->where('status', 9)
                $is_fstatus && $builder->where('fstatus', 1);
                $builder->where('id>', (int)$data['id'])->orderBy('id asc');
                $data['next_page'] = $builder->limit(1)->get()->getRowArray();
                if (isset($data['next_page']['url']) && $data['next_page']['url']) {
                    $data['next_page']['url'] = dr_url_prefix($data['next_page']['url'], $this->module['dirname'], SITE_ID, $this->is_mobile);
                }
            }
    
            return $data;
        }


    4.5.3Content类的_call_show
      // 内容页面的字段格式化处理
        protected function _Show_Data($data, $page) {
    
            // 处理关键字标签
            $data['tag'] = $data['keywords'] = trim($data['keywords']);
            $data['kws'] = [];
            $data['tags'] = [];
            if ($data['keywords']) {
                $tag = explode(',', $data['keywords']);
                $obj = false;
                if (dr_is_app('tag')) {
                    // 是否安装tag
                    $obj = \Phpcmf\Service::M('tag', 'tag');
                    if (!method_exists($obj, 'get_tag_url')) {
                        $obj = false;
                    }
                }
                foreach ($tag as $t) {
                    $t = trim($t);
                    if ($t) {
                        // 读缓存
                        if ($obj) {
                            $url = $obj->get_tag_url($t);
                            if ($url) {
                                $data['tags'][$t] = $url;
                            }
                        }
                        $data['kws'][$t] = \Phpcmf\Service::L('router')->search_url([], 'keyword', $t, MOD_DIR);
                    }
                }
            }
    
            // 关闭插件嵌入
            $is_fstatus = dr_is_app('fstatus') && isset($this->module['field']['fstatus']) && $this->module['field']['fstatus']['ismain'] ? 1 : 0;
    
            // 上一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->content_model->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id<', (int)$data['id'])->orderBy('id desc');
            $data['prev_page'] = $builder->limit(1)->get()->getRowArray();
            if (isset($data['prev_page']['url']) && $data['prev_page']['url']) {
                $data['prev_page']['url'] = dr_url_prefix($data['prev_page']['url'], $this->module['dirname'], SITE_ID, $this->is_mobile);
            }
    
            // 下一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->content_model->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id>', (int)$data['id'])->orderBy('id asc');
            $data['next_page'] = $builder->limit(1)->get()->getRowArray();
            if (isset($data['next_page']['url']) && $data['next_page']['url']) {
                $data['next_page']['url'] = dr_url_prefix($data['next_page']['url'], $this->module['dirname'], SITE_ID, $this->is_mobile);
            }
    
            // 格式化输出自定义字段
            $fields = $this->module['category_data_field'] ? array_merge($this->module['field'], $this->module['category_data_field']) : $this->module['field'];
            $fields['inputtime'] = ['fieldtype' => 'Date'];
            $fields['updatetime'] = ['fieldtype' => 'Date'];
    
            // 格式化字段
            $data = \Phpcmf\Service::L('Field')->app($this->module['dirname'])->format_value($fields, $data, $page);
    
            // 模块的回调处理
            $data = $this->content_model->_call_show($data);
    
            return $data;
        }
    我是觉得4.5.3时候 模块回调得放在最后面比较合理的吧
  • 亿友
    #3楼    亿友
    2022-02-10 21:07:11
    Chrome 0
    我的模块重写代码 上面帖子有个var_dumo请忽略他,不是这边问题
    
    <?php
    namespace Phpcmf\Model\News;
    
    // 模块内容模型类
    
    class Content extends \Phpcmf\Model\Content {
    
       
        
        // 格式化处理内容
        public function _call_show($data) {
            // 上一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id<', (int)$data['id'])->where('inputtime<=', time())->orderBy('id desc');
            $data['prev_page'] = $builder->limit(1)->get()->getRowArray();
    
    
            // 下一篇文章
            $builder = \Phpcmf\Service::M()->db->table($this->mytable);
            $builder->where('catid', (int)$data['catid'])->where('status', 9);
            $is_fstatus && $builder->where('fstatus', 1);
            $builder->where('id>', (int)$data['id'])->where('inputtime<=', time())->orderBy('id asc');
    
            $data['next_page'] = $builder->limit(1)->get()->getRowArray();
    
            return $data;
        }
    }
  • #4楼    迅睿框架创始人
    2022-02-10 21:09:21
    Google Pixel 手机 0
    加一个 $this->is_prev_next_page = 0;
  • 优速-有偿帮忙解决问题
    #5楼    优速-有偿帮忙解决问题
    2022-02-10 21:10:55
    Chrome 0
     $data['prev_page']改成  $data['prev_page2']
     换一个名字
    满意答案
  • 亿友
    #6楼    亿友
    2022-02-10 21:16:44
    Chrome 0
    回复迅睿框架创始人 return $data; 加在这个上面?不行如果要调整回来,可以等新版更新
  • 亿友
    #7楼    亿友
    2022-02-10 21:18:52
    Chrome 0
    优速-有偿帮忙解决问题 这样改模板上面调用也要改的吧?
  • #8楼    迅睿框架创始人
    2022-02-10 21:22:16
    Google Pixel 手机 0
    不会更新这个,推荐用5楼的方法,改一个名字
  • 亿友
    #9楼    亿友
    2022-02-10 21:39:57
    Chrome 0
    Content类的_call_show就把这个调到最下面 这个调整下位置好像也不影响其他,会不会更好?回调就可以控制所有的$data的了
            
            // 模块的回调处理
            $data = $this->content_model->_call_show($data);
    
            return $data;
    回复迅睿框架创始人
  • 亿友
    #10楼    亿友
    2022-04-17 21:41:34
    Chrome 0
    @优速-有偿帮忙解决问题:如果官方不更改,只能改名才能不影响后续升级