|
控制器
PHP复制代码 <?php
class Class_Controller extends Controller {
public $adminDate = FALSE;
public $classArray = FALSE;
public $classtree = FALSE;
function __construct (){
parent ::__construct ();
// $this->session = Passport::chkadmin();
}
public function index ($bclassid = 0){
$view = new View ('class_list');
$db = new Database ();
$this -> classArray = $db -> select("*") -> from('class') -> orderby('myorder','asc') -> orderby('classid','asc') -> get() -> result_array(FALSE);
if ( count( $this -> classArray ) > 0 ){
$tmpTree = array();
foreach ( $this -> classArray as $tmpclass ){
$tmpTree[$tmpclass['bclassid']][] = $tmpclass;
}
$this -> classtree = $tmpTree;
$myclass = $this -> _listclass ($bclassid);
$view -> set ( 'list' , $myclass );
}
$view -> render(TRUE);
}
public function _listclass ($bclassid=0){
$bclassid = (int )$bclassid;
if($bclassid > 0){}else{$bclassid=0;}
$tmpclass =$this -> classtree [$bclassid];
if ( count( $tmpclass ) > 0 ){
foreach ( $tmpclass as $r ){
$classarray[ $r['classid'] ] = $r;
$classarray[ $r['classid'] ]['sonclass'] = $this -> _listclass ( $r['classid'] );
}
return $classarray;
}
}
public function edit ($id=0){
$view = new View ('class_add');
if ($id>0){
$view -> title = '修改栏目';
$db = new Database ();
$result = $db->from('class')->where(array('classid' => $id)) -> limit(1) -> get() -> result_array(FALSE);
if ($result){
$view -> set('class',$result[0]);
}
}else{
$view -> title = '新增栏目';
}
$view -> render(TRUE);
}
}
复制代码
视图文件class_list.php
PHP复制代码 <table border="0" cellpadding="3" cellspacing="1" width="96%" align="center" class="tableborder">
<tr>
<th class="td1" width="40"><b>排序</b></th>
<th class="td1" width="50"><b>ID</b></th>
<th class="td1"><b>栏目名称</b></th>
<th class="td1" width="60"><b>访问次数</b></th>
<th class="td1" width="200"><b>操作</b></th>
</tr>
<?php
$count_i = 0;
function listclass ($list,$spacer=''){
global $count_i;
if($list):
$countlist = count($list);
$i = 0;
foreach ($list as $item):
$i++;
$count_i++;
if ($item['islast'] ==0){
if ($item['sonclass']){
$spacer1 = $spacer .'<img src="/images/tree_add.gif" align="absmiddle" /> ';
}
else{
$spacer1 = $spacer .'<img src="/images/tree_del.gif" align="absmiddle" /> ';
}
}else{
$spacer1 = $spacer .' ';
}
?>
<tr <?php if($count_i%2==0){echo ' class="td3"';} ?>>
<td class="td1" align="center"><input type="text" size="3" id="paixu_ <?=$item['classid']?>" value=" <?=$item['myorder']?>" /></td>
<td class="td1" align="center"> <?=$item['classid']?></td>
<td class="td2"> <?=$spacer1?><img src="/images/ <?=$item['islast']? 'ie':'dir';?>.gif" align="absmiddle" /><a href" <?=$item['id']?>/" target="_blank"> <?=$item['classname']?></a></td>
<td class="td2" align="center"> <?=$item['hits']?></td>
<td class="td2" align="center"><input onclick="goUrl(' <?=url ::site('class/edit/'.$item['classid']) ?>')" type="button" value="修改栏目" class="btn" /> <input onclick="goUrl(' <?=url ::site('class/del/'.$item['id'])?>','hiddenFrame')" type="button" value="删除栏目" class="btn" /></td>
</tr>
<?php
//echo ($i+1).'|'.$countlist.'|'.$item['classname'];
if ($item['sonclass']){
$spacer .= ' ';
listclass ($item['sonclass'],$spacer);
$spacer = substr($spacer,0,-strlen(' '));
}
endforeach;
endif;
}
listclass ($list);
?>
<tr>
<td class="td1" colspan="5">
<input onclick="goUrl(' <?=url ::site('notice/send') ?>')" type="button" value="修改栏目顺序" class="btnl" />
</td>
</tr>
</table>
复制代码
MYSQL
SQL复制代码 # MySQL-Front 3.2 (Build 13.16)
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET TIME_ZONE='SYSTEM' */;
# Host: localhost DATABASE: myqeeunion
# ------------------------------------------------------
# Server version 5.0.41-community-nt
/*!40101 SET NAMES utf8 */;
#
# TABLE STRUCTURE FOR TABLE my_class
#
DROP TABLE IF EXISTS `my_class`;
CREATE TABLE `my_class` (
`classid` INT(11) NOT NULL AUTO_INCREMENT,
`bclassid` INT(11) DEFAULT NULL,
`classname` VARCHAR(50) DEFAULT NULL,
`sonclass` text,
`islast` tinyint(1) DEFAULT NULL,
`hits` INT(11) DEFAULT NULL,
`classpath` text,
`classtype` VARCHAR(20) DEFAULT NULL,
`timeline` INT(11) DEFAULT NULL,
`myorder` SMALLINT(6) DEFAULT NULL,
PRIMARY KEY (`classid`),
KEY `bclassid` (`bclassid`)
) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
#
# Dumping DATA FOR TABLE my_class
#
INSERT INTO `my_class` VALUES (1,0,'手机小说','|10|11|12|13|14|15|',0,0,'book','.html',NULL,0);
INSERT INTO `my_class` VALUES (2,1,'玄幻·奇幻','|10|11|12|13|14|15|',0,0,'book/xuanhuan','.html',NULL,0);
INSERT INTO `my_class` VALUES (3,1,'武侠·仙侠','',0,0,'book/wuxia','.html',NULL,0);
INSERT INTO `my_class` VALUES (4,1,'都市·言情','',0,0,'book/yanqing','.html',NULL,0);
INSERT INTO `my_class` VALUES (5,1,'历史·军事','',0,0,'book/junshi','.html',NULL,0);
INSERT INTO `my_class` VALUES (6,1,'游戏·竞技','',0,0,'book/youxi','.html',NULL,0);
INSERT INTO `my_class` VALUES (7,1,'科幻·灵异','',0,0,'book/lingyi','.html',NULL,0);
INSERT INTO `my_class` VALUES (8,1,'美文·同人','',0,0,'book/meiwen','.html',NULL,0);
INSERT INTO `my_class` VALUES (9,1,'剧本·全文','',0,0,'book/juben','.html',NULL,0);
INSERT INTO `my_class` VALUES (10,2,'异世大陆','',1,0,'book/xuanhuan/yijie','.html',NULL,0);
INSERT INTO `my_class` VALUES (11,2,'西方奇幻','',1,0,'book/xuanhuan/xifang','.html',NULL,0);
INSERT INTO `my_class` VALUES (12,2,'东方玄幻','',1,0,'book/xuanhuan/dongfang','.html',NULL,0);
INSERT INTO `my_class` VALUES (13,2,'异术超能','',1,0,'book/xuanhuan/yishu','.html',NULL,0);
INSERT INTO `my_class` VALUES (14,2,'远古神话','',1,0,'book/xuanhuan/yuangu','.html',NULL,0);
INSERT INTO `my_class` VALUES (15,2,'魔法校园','',1,0,'book/xuanhuan/mofa','.html',NULL,0);
/*!40101 SET NAMES utf8 */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
复制代码
再发一个效果图上来 |
-
评分
-
查看全部评分
|