各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案

Str Tom,为分享PHP技术和解决方案,贡献一份自己的力量!
收藏本站(不迷路),每天更新好文章!
当前位置:首页 > CMS教程 > phpcms

V9增加打印模板和打印预览功能

管理员 2022-08-28
phpcms
318
在内容模型里创建文件(即phpcmsmodulescontent目录下)
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
pc_base::load_app_func('util','content');
class printr {
        private $db;
        function __construct() {
                $this->db = pc_base::load_model('content_model');
                $this->_userid = param::get_cookie('_userid');
                $this->_username = param::get_cookie('_username');
                $this->_groupid = param::get_cookie('_groupid');
        }
       
        //内容页
        public function show() {
                $catid = intval($_GET['catid']);
                $id = intval($_GET['id']);

                $siteids = getcache('category_content','commons');
                $siteid = $siteids[$catid];
                $CATEGORYS = getcache('category_content_'.$siteid,'commons');
               
                $this->category = $CAT = $CATEGORYS[$catid];
                $this->category_setting = $CAT['setting'] = string2array($this->category['setting']);
                $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
               
                $MODEL = getcache('model','commons');
                $modelid = $CAT['modelid'];
               
                $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
                $r = $this->db->get_one(array('id'=>$id));
                if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');
               
                $this->db->table_name = $tablename.'_data';
                $r2 = $this->db->get_one(array('id'=>$id));
                $rs = $r2 ? array_merge($r,$r2) : $r;

                //再次重新赋值,以数据库为准
                $catid = $CATEGORYS[$r['catid']]['catid'];
                $modelid = $CATEGORYS[$catid]['modelid'];
               
                require_once CACHE_MODEL_PATH.'content_output.class.php';
                $content_output = new content_output($modelid,$catid,$CATEGORYS);
                $data = $content_output->get($rs);
                extract($data);

                include template('content','print_r');
        }
       
}
?>


内容模型的模板文件按照模型指定的名字来建,如上面指定的是print_r.html文件,然后在这个文件就可以输出你想要的内容页的指定字段内容进行打印预览了,
需要打印功能的页面加上:<a href="{APP_PATH}index.php?m=content&c=printr&a=show&catid={$catid}&id={$id}">打印</a>

打印页的样式可以完全按照内容页的代码去调用内容!


扫码关注

qrcode

QQ交谈

回顶部