您好,登錄后才能下訂單哦!
首先,模塊開發需要了解五指cms的目錄結構:
然后,我們需要新增加一個模塊目錄:
再app下面創建
如:content
下面包含文件:
前臺文件的創建:
看下 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架構。
后臺文件的創建:
首先登錄后臺,添加后臺菜單:
路徑:維護界面>后臺菜單管理>
在擴展模塊欄目:添加子菜單。
添加完成后,就會在對應的菜單下面找到。
后臺文件的編寫:
后臺文件一定要放置到 admin目錄。
在:模塊目錄下:coreframe/app/link/admin/下面添加文件。
具體可以參考下:
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', '', '*', 0, 20,$page,'sort ASC'); $pages = $this->db->pages; $total = $this->db->number; include $this->template('listing'); }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。