自定义定制模块
author:一佰互联 2020-10-12   click:149

一、建立数据库表

 admin目录下增加后台录入功能,可以参考jobs目录,列表,增加,删除,修改功能

二、模块化--增加PHP代码:

根目录下首页index.php,mobile/index.php(单独手机版)及 admin/edittpl/index.php,admin/edittpl/mobile/index.php(单独手机版),4个PHP文件都要布置相同的PHP代码

在以上文件中搜索if($row_c[\'note_class\']==\'jobs\' )在他上边加入其它模块判断示例:

//自定义模块示例

if($row_c[\'note_class\']==\'我定义模块类型名(英文)\' ){

//lang语言,web站点,$offset,$pageSize分页参考下边新闻列表

$query =\"select * from 表 where 条件  and lang=\'$lang\' and user=\'$web\'   ORDER BY  limit $offset,$pageSize\";
$rs2=$DB->query($query2);

.................

}
//页面已经有的招聘模块代码参考:



 //如果为招聘模块

if($row_c[\'note_class\']==\'jobs\' )
 {
//---------------分页组装-----------------------无需分页可删除
$sql3 = \"select count(*) from jobs where showIndex=1 and lang=\'$lang\' and user=\'$web\' \";
$rs3  = $db->query($sql3);//执行SQL
$pageSize = 10;//每页数量
$totalRecord = $db->result($rs3,0,0);//计算出总数
$totalPage = @ceil($totalRecord/$pageSize);//计算出总页数
$noteid=$row_c[\'id\'];//当前模块分页标志组装
$page_variable_name=\"page\".$noteid;
$page=strFilter($_GET[$page_variable_name]);
$page=verify_id($page);//前面已经定义过了用户传入的page当前页码
if(!$page)$page = 1;
$offset = ($page-1)*$pageSize;

$pageList = GetPageList($_SERVER[\'PHP_SELF\'],$page_variable_name,$listnum?$listnum:\"4\",$totalPage,$page);

$pagers=\"{$langInfo[\'gong\']} $totalRecord {$langInfo[\'gong1\']} $totalPage {$langInfo[\'gong2\']} $page {$langInfo[\'gong3\']}\";
if($pageList) $pagers.= \" <br><br>$pageList[0] $pageList[1]\";

//---------------查询出所有招聘信息-----------------------
$query2 =\"select * from jobs where showIndex=1  and lang=\'$lang\' and user=\'$web\'   ORDER BY dtCreate asc limit $offset,$pageSize\";
$rs2=$DB->query($query2);

//---------遍历结果集--------并分配到模块$produ数组供smarty模版调用

while($row_p=$db->fetch_array($rs2)){

//对字段进行处理
  $row_p[\'dtCreate\'] = $row_p[\'dtCreate\'];
  $row_p[\'month\'] = date(\"m\",strtotime($row_p[\'dtCreate\']));
  $row_p[\'day\'] = date(\"d\",strtotime($row_p[\'dtCreate\']));
$Contentall1=$row_p[\'Content\'];
$row_p[\'Content\'] = cutStr($row_p[\'Content\'],40).\"...\";
$Contentall=$row_p[\'Content\'];
$row_p[\'Title\'] = mb_substr($row_p[\'Title\'],0,$news_btzs,\'utf8\').\"\";
$row_p[\'year\'] = date(\"Y\",strtotime($row_p[\'dtCreate\']));

//所有结果集分配到$produ[]数组
$produ[]=array(\"fuli\"=>$row_p[\'fuli\'],\"fee\"=>$row_p[\'fee\'],\"address\"=>$row_p[\'address\'],\"nub\"=>$row_p[\'nub\'],\"edu\"=>$row_p[\'edu\'],\"jinyan\"=>$row_p[\'jinyan\'],\"month\"=>$row_p[\'month\'] ,\"year\"=>$row_p[\'year\'] ,\"day\"=>$row_p[\'day\'] ,\"id\"=>$row_p[\'id\'],\"Title\"=>$row_p[\'Title\'],\"Content\"=>$row_p[\'Content\'],\"dtCreate\"=>date(\'Y-m-d\',strtotime($row_p[\'dtCreate\'])),\"Contentall\"=>$Contentall,\"Contentall1\"=>$Contentall1); 
 
}

}



三、模块化---自定义模板文件设置

在模板目录新建html文件,写法参见job_list.html:

1、遍历语法参smarty官方section循环{{section name=plist loop=$class[clist].produ}}其中produ即为前面定义的数组

2、$class[clist]是上层遍历直接使用(表示当前模块)

//CSS代码,.note{{$class[clist].id}}

 <style>
 .note{{$class[clist].id}} .th{background:#f4f4f4;margin-bottom:35px}
 .note{{$class[clist].id}} .th td{border:1px solid #ddd;text-align:center;font-size:1.4rem;padding:10px 0;}
 .note{{$class[clist].id}} .list{border-bottom:1px dashed #ddd;line-height:40px;}
  .note{{$class[clist].id}}  .list td{text-align:center;font-size:1.2rem;color:#555}
 </style>


//plist当前遍历取名(自定义)
<table style=\"margin-bottom:25px;background:none;\" class=\"csstable\">
<tr class=\"th\" style=\"\"><td>岗位名称</td>
<td>工作经验/学历/人数</td>
<td>工作地点</td>
<td>薪资</td>
<td>发布时间</td>

</tr>

{{section name=plist loop=$class[clist].produ}}
<tr class=\"list\" >
<td style=\"font-size:1.4rem\">{{$class[clist].produ[plist].Title}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].jinyan}}/{{$class[clist].produ[plist].edu}}/{{$class[clist].produ[plist].nub}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].address}}</td>
<td style=\"color:#ff7230;font-size:1.6rem;\">{{$class[clist].produ[plist].fee}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].dtCreate}}</td>
</tr>
<tr class=\"\" ><td colspan=\"5\" style=\"text-align:left;padding:10px;border:0 \">{{$class[clist].produ[plist].Contentall1}}</td></tr>

{{/section}}

</table>

<!----分页代码插入--->
<div class=\"pagination\" id=\"J_newsPagination\" style=\"padding-top: 50px;\">
                 <div name=\"laypage1.3\" class=\"laypage_main laypageskin_default\" id=\"laypage_0\">
                   <div class=\'page\'>
                    {{$class[clist].pagers}}
                   </div>
                 </div>
</div>





四、模块系统引入你定义的文件


在skin/h5-default模板目录中打开note_class.html,引入你的模板文件。

增加如下代码:{{elseif  $class[clist].note_class==\"你定义模块类型名(英文)\"}}{{include file=\"你写的模板文件名.html\"}},系统执行到这里会判断如果模块为你定义的类型名即执行你上边创建的的html文件。





五、在skin/h5-default模板目录中打开system_2.html,搜索点击模块-拖拽添加,加入增加模块的风格选择示例:

 <div class=\"contents searchdivpad\" id=\'\'>
                            <div class=\"itembox\" note_class=\"product\" pro_ms=\"1\">
                                <img src=\"/static/mbimg/product_6.png\" style=\"width:250px\">
                            </div>
</div>


1、note_class=\"前你你定义的模块类别取名\"

2、pro_ms=\"1\" 如果有多种风格在自定义模板文件中加入判断

{{if  $class[clist]==\"1\" }}

<!----风格一代码--->

 <style>
 .note{{$class[clist].id}} .th{background:#f4f4f4;margin-bottom:35px}
 .note{{$class[clist].id}} .th td{border:1px solid #ddd;text-align:center;font-size:1.4rem;padding:10px 0;}
 .note{{$class[clist].id}} .list{border-bottom:1px dashed #ddd;line-height:40px;}
  .note{{$class[clist].id}}  .list td{text-align:center;font-size:1.2rem;color:#555}
 </style>


//plist当前遍历取名(自定义)
<table style=\"margin-bottom:25px;background:none;\" class=\"csstable\">
<tr class=\"th\" style=\"\"><td>岗位名称</td>
<td>工作经验/学历/人数</td>
<td>工作地点</td>
<td>薪资</td>
<td>发布时间</td>
</tr>

{{section name=plist loop=$class[clist].produ}}
<tr class=\"list\" >
<td style=\"font-size:1.4rem\">{{$class[clist].produ[plist].Title}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].jinyan}}/{{$class[clist].produ[plist].edu}}/{{$class[clist].produ[plist].nub}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].address}}</td>
<td style=\"color:#ff7230;font-size:1.6rem;\">{{$class[clist].produ[plist].fee}}</td>
<td style=\"font-size:1.4rem;\">{{$class[clist].produ[plist].dtCreate}}</td>
</tr>
<tr class=\"\" ><td colspan=\"5\" style=\"text-align:left;padding:10px;border:0 \">{{$class[clist].produ[plist].Contentall1}}</td></tr>

{{/section}}

</table>

<!----分页代码插入--->
<div class=\"pagination\" id=\"J_newsPagination\" style=\"padding-top: 50px;\">
                 <div name=\"laypage1.3\" class=\"laypage_main laypageskin_default\" id=\"laypage_0\">
                   <div class=\'page\'>
                    {{$class[clist].pagers}}
                   </div>
                 </div>
</div>



{{elseif  $class[clist]==\"2\" }}

风格二代码

...............

{{else}}

其它

..............

{{/if}}


六、上边只是录入、展现,其它逻辑自行开发。

网站目录下user用户目录,product普通产品定单,vhost网站产品,common下Order.class.php定义类。