温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

wuzhicms 模块开发

发布时间:2020-07-25 09:42:51 阅读:721 作者:zhw810 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

首先,模块开发需要了解五指cms的目录结构:

然后,我们需要新增加一个模块目录:

再app下面创建


wuzhicms 模块开发

如:content

下面包含文件:
wuzhicms 模块开发

前台文件的创建:

看下 index.php 的内容:

<?php// +----------------------------------------------------------------------// | wuzhicms [ 五指互联网站内容管理系统 ]// | Copyright (c) 2014-2015 http://www.wuzhicms.com All rights reserved.// | Licensed ( http://www.wuzhicms.com/licenses/ )// | Author: wangcanjia// +----------------------------------------------------------------------defined('IN_WZ') or exit('No direct script access allowed');load_function('content','content');/** * 网站首页 */class index{    private $siteconfigs;   public function __construct() {        $this->siteconfigs = get_cache('siteconfigs');        $this->db = load_class('db');   }    /**     * 网站首页     */    public function index() {        $isindex = 1;        $siteconfigs = $this->siteconfigs;        $seo_title = $siteconfigs['sitename'];        $seo_keywords = $siteconfigs['seo_keywords'];        $seo_description = $siteconfigs['seo_description'];        $categorys = get_cache('category','content');        include T('content','index',TPLID);   }    /**     * 内容页面     * url规则 /index.php?v=show&cid=24&id=79     */    public function show() {        $siteconfigs = $this->siteconfigs;        $id = isset($GLOBALS['id']) ? intval($GLOBALS['id']) : MSG(L('parameter_error'));        $cid = isset($GLOBALS['cid']) ? intval($GLOBALS['cid']) : MSG(L('parameter_error'));        $categorys = get_cache('category','content');        //查询数据        $category = get_cache('category_'.$cid,'content');        $models = get_cache('model_content','model');        $model_r = $models[$category['modelid']];        $master_table = $model_r['master_table'];        $data = $this->db->get_one($master_table,array('id'=>$id));        if(!$data || $data['status']!=9) MSG('信息不存在或者未通过审核!');        if($model_r['attr_table']) {            $attr_table = $model_r['attr_table'];            if($data['modelid']) {                $modelid = $data['modelid'];                $attr_table = $models[$modelid]['attr_table'];            }            $attrdata = $this->db->get_one($attr_table,array('id'=>$id));            $data = array_merge($data,$attrdata);        }        require get_cache_path('content_format','model');        $form_format = new form_format($model_r['modelid']);        $data = $form_format->execute($data);        foreach($data as $_key=>$_value) {            $$_key = $_value['data'];        }        if($template) {            $_template = $template;        } elseif($category['show_template']) {            $_template = $category['show_template'];        } elseif($model_r['template']) {            $_template = TPLID.':'.$model_r['template'];        } else {            $_template = TPLID.':show';        }        $styles = explode(':',$_template);        $project_css = isset($styles[0]) ? $styles[0] : 'default';        $_template = isset($styles[1]) ? $styles[1] : 'show';        $elasticid = elasticid($cid);        $seo_title = $title.'_'.$category['name'].'_'.$siteconfigs['sitename'];        $seo_keywords = !empty($keywords) ? implode(',',$keywords) : '';        $seo_description = $remark;        //上一页        $previous_page = $this->db->get_one($master_table,"`cid`= '$cid' AND `id`>'$id' AND `status`=9",'*',0,'id ASC');        //下一页        $next_page = $this->db->get_one($master_table,"`cid` = '$cid' AND `id`<'$id' AND `status`=9",'*',0,'id DESC');        include T('content',$_template,$project_css);    }    /**     * 栏目列表     */    public function listing() {        $cid = isset($GLOBALS['cid']) ? intval($GLOBALS['cid']) : MSG(L('parameter_error'));        //站点信息        $siteconfigs = $this->siteconfigs;        //栏目信息        $categorys = get_cache('category','content');        $category = get_cache('category_'.$cid,'content');        //分页初始化        $page = max(intval($GLOBALS['page']),1);        //分页规则        $urlrule = '';        if($category['child']) {            $_template = $category['category_template'];        } else {            $_template = $category['list_template'];        }        if(empty($_template))  $_template = TPLID.':list';        $styles = explode(':',$_template);        $project_css = isset($styles[0]) ? $styles[0] : 'default';        $_template = isset($styles[1]) ? $styles[1] : 'show';        $seo_title = $category['name'].'_'.$siteconfigs['sitename'];        $seo_keywords = $category['seo_keywords'];        $seo_description = $category['seo_description'];        $elasticid = elasticid($cid);        $model_r = get_cache('model_content','model');        $master_table = $model_r[$category['modelid']]['master_table'];        if($category['type']==1) {            $r = $this->db->get_one($master_table,array('cid'=>$cid));            if($r) {                extract($r,EXTR_SKIP);                if($attr_table = $model_r[$category['modelid']]['attr_table']) {                    $r = $this->db->get_one($attr_table,array('id'=>$id));                    extract($r,EXTR_SKIP);                }            }        }        include T('content',$_template,$project_css);    }}?>

完整的访问路径:
http://www.wuzhicms.com/index.php?m=content&f=index&v=listing&cid=2

通过参数:m=content //模块名
f=index //文件名(控制器)
v=方法名(视图)

这个就是MCV架构。

后台文件的创建:

     首先登录后台,添加后台菜单:

路径:维护界面>后台菜单管理>

wuzhicms 模块开发

在扩展模块栏目:添加子菜单。

wuzhicms 模块开发

添加完成后,就会在对应的菜单下面找到。


wuzhicms 模块开发

后台文件的编写:

后台文件一定要放置到 admin目录。


在:模块目录下:coreframe/app/link/admin/下面添加文件。

wuzhicms 模块开发

具体可以参考下:

defined('IN_WZ'or exit('No direct script access allowed');
/**
 * 友情链接
 */
load_class('admin');
class index extends WUZHI_admin {
   private $db;

   function __construct({
      $this->db = load_class('db');
   }
    /**
     * 友情链接列表
     */
    public function listing() {
        $page isset($GLOBALS['page']) ? intval($GLOBALS['page']) : 1;
        $page max($page,1);
        $result $this->db->get_list('link''''*'020,$page,'sort ASC');
        $pages $this->db->pages;
        $total $this->db->number;
        include $this->template('listing');
    }

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×