开始工作很多天了,上周五下班之前对上周的任务进行了赶时间的完工,实际上是师傅自己做的。花了快一个星期做出来的的东西后来发现是做的一塌糊涂,从css的排版到思考方式都是问题重重,不够简练不够清晰不够专业,昨天有安排下来新的任务可是我却完全没有理解更别谈思路了,所以现在虽然是任务在身可是却是相当闲的,趁这个时机我来整理下自己前一段时间的心得吧。
我的任务是对一个后台网页下的子菜单下再另添加一个前台网站开关,从下面两个方向分析一下:
第一,我的思路和做法,思路很简单,因为是子菜单,所以按照其他的子菜单进行大量的复制过来再进行修改即可。补充一下,整个网站是在MVC架构下搭建的,所以我花了很多时间去熟悉去理解自己写下的php应该放在哪个文件夹下,所谓的MVC,M是业务模型(这一块上个任务我基本上是零接触),V是view用户界面(在我们正在做的这个网站里是创建的WEB文件夹,这个则是放置处理的后台界面的php文件),C是controller控制器(类似V的是backend文件夹)。实际上整个网站的后台代码文件夹有很多,例如domain文件夹,这个存放的是这个后台网站所操控的所有的前台网站的域名和地址,我要达到的目标就是通过后台的网页上面的网站开关对这个文件夹里的某一个域名存放的txt的文件内容进行修改,让二级客户在网站进行升级阶段无法进入,但是一级客户如果有需要的话可以通过自己在地址上添加index进入查看。例如这个名为bz.sotxsports.com.txt的文件它的内容如下:{"site_path":"default","default_a":"index","default_url":"\/?a=e.upgrade&sid=1674433","status":"1"}它定义了默认的域名首页,要实现网站开关则是需要把"default_url":"\/?a=e.index&sid=1674433"修改为"default_url":"\/?a=e.upgrade&"sid=1674433"这个过程是用php实现的。我查到的办法是通过fwrite对这个文件写入。然后其他的部分大多是拷贝代码并添加和修改,代码将在后面写出。
第二,最终的代码.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 |
//CENTER_C.webon.php<br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <meta http-equiv= "Content-Type"
content= "text/html; charset=utf-8"
/> <link rel= "shortcut icon"
href= "<?php echo $hostShopIco;?>"
/> <title>网站开关—商户中心-<?php echo
$shop_page_title ;?></title> <link href= "<?php echo CENTER_W?>style/common.css"
rel= "stylesheet"
type= "text/css"
/> <link href= "<?php echo CENTER_W?>style/layout.css"
rel= "stylesheet"
type= "text/css"
/> <script type= "text/javascript"
src= "<?php echo CENTER_W?>js/jquery.js" ></script> <script type= "text/javascript"
src= "<?php echo CENTER_W?>js/validate.js" ></script> <script type= "text/javascript"
src= "<?php echo CENTER_W?>js/plus.js" ></script> <script type= "text/javascript"
src= "<?php echo CENTER_W?>js/trader.js" ></script> <script> $( function (){ if (<?php echo
$status ;?>) $( "input[value=‘1‘]" ).attr( "checked" ,true); else $( "input[value=‘0‘]" ).attr( "checked" ,true); $( "#site_switchSubmit" ).click( function (){ $.ajax( { url: "/?a=center.account.webon" , type: "post" , data: { flag:$( "input[name=‘radiobutton‘]:checked" ).val() }, dataType: "json" , success: function (rs) { alert(rs.msg); } }) }) }) </script> </head> <body> <span style= "text-decoration: underline;" ><strong><div class = "tab"
style= "margin:0" > <?php require
CENTER_V . ‘account/topnav.php‘ ; ?></strong></span> </div> <div> <label>网店:</label> <input type= "radio"
name= "radiobutton"
value= "1" >开启 <input type= "radio"
name= "radiobutton"
value= "0" >关闭<br> </div> <div class = "button" > <input class = "minInputBtn minBlue"
id= "site_switchSubmit"
type= "submit"
value= "提 交" /> </div> </body><br><br></html> |
1
2
3
4
5
6
7
8
9
10 |
//CETER_V.topnav.php<br><ul> <?php $url_arr
= explode ( ‘.‘ , $_REQUEST [ ‘a‘ ]); $_a
= array_pop ( $url_arr ); ?> <li class = "tabStable" ><a <?php echo
$_a == ‘updatepassword‘
? ‘class="current"‘
: ‘‘ ;?> href= "?a=center.account.updatepassword" >修改密码</a></li> <li class = "tabStable" ><a <?php echo
$_a == ‘bindemail‘
? ‘class="current"‘
: ‘‘ ;?> href= "?a=center.account.bindemail" >密保邮箱</a></li> <li class = "tabstable" ><a <?php echo
$_a == ‘site_switch‘
? ‘class="current"‘ : ‘‘ ;?> href= "?a=center.account.site_switch" >网站开关</a></li> </ul> |
1
2
3
4
5
6 |
//CENTER_V.upgrade.php<br><?php //已经传了一个sid变量和template变量,m变量 $tempPath = $_SITE_PATH_ . "web/enterpriseMod/$template/upgrade.html" ; $tempContent = file_get_contents ( $tempPath ); echo ( $tempContent ); ?> |
//upgrade.html
<!doctype html>
<html>
<head><meta
http-equiv="Content-Type" content="text/html; charset=utf-8"
/></head>
<body>
<div>网站正在升级中给您带来不便恳请谅解!</div>
<a
href="/?a=e.index&sid=1674433"
target="_blank">如果您有需要点此进入查看!</a>
</body>
</html>
1 |
|
1
2
3
4
5
6
7
8
9
10 |
//CENTER_C.site_switch.php<br><?php $str
= file_get_contents ( "domain/bz.sotxsports.com.txt" ); $status =1; if ( strpos ( $str , "e.index" )===false) { $status =0; } require_once
CENTER_V. ‘account/site_switch.php‘ ; ?> |
//webon.php
<?php //$path="domain/".$hostShopUrl.".txt";
$path = "domain/bz.sotxsports.com.txt";
$content = file_get_contents($path);
$arr = json_decode($content);
if($_POST[‘flag‘]) {
$arr->default_url=str_replace("upgrade","index",$arr->default_url);
} else { $arr->default_url=str_replace("index","upgrade",$arr->default_url); }
$flag = file_put_contents($path,json_encode($arr));
$rs=new stdClass();
if($flag) {
$rs->type="success"; $rs->msg="操作成功";
} else {
$rs->type="success"; $rs->msg="操作失败";
}
echo json_encode($rs);
?>
原文:http://www.cnblogs.com/isuben/p/3623190.html