栏目分类【微服务】

数据结构

CREATE TABLE IF NOT EXISTS `ims_adv_years_cate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `weid` int(11) NOT NULL,
  `listorder` int(11) NOT NULL,
  `title` varchar(20) NOT NULL,
  `desc` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;


操作site

public function doWebCate() {
        global $_GPC, $_W;
		$table='adv_years_cate';
		$op=empty($_GPC['op'])?'display':$_GPC['op'];
		if($_GPC['op']=='post'){
			$field=array('listorder','title','desc');
			$id=intval($_GPC['id']);
			if($_W['ispost']){
				//保存数据
				foreach($field as $v){
					$insert[$v]=$_GPC[$v];
				}
				if($id>0){
					$temp=pdo_update($table, $insert, array('id' => $id,'weid'=>$_W['weid']));
				}else{
					$insert['weid']=$_W['weid'];
					$temp=pdo_insert($table,$insert);
				}
				if($temp===false){				
					message('抱歉,数据操作失败!','', 'error');              
				}else{
					message('更新数据成功!', $this->createWeburl('cate'), 'success');
				}
			}
			if($id>0){
				$item=pdo_fetch('select * from '.tablename($table).' where weid=:weid AND id=:id',array(':weid'=>$_W['weid'],':id'=>$id));
			}	
			if($item==false){
				//初始数值
				$item=array(
					'listorder'=>0
				);	
			}
		}elseif($op=='delete'){
			$id=intval($_GPC['id']);
			if(empty($id)){
				message('参数错误,请确认操作');
			}
			$temp = pdo_delete($table,array('id'=>$id,'weid'=>$_W['weid']));
			if($temp==false){
				message('抱歉,刚才修改的数据失败!','', 'error');              
			}else{
				message('删除数据成功!',$this->createWeburl('cate'), 'success');      
			}	
			
		}elseif($op=='display'){
			if($_W['ispost']){
				if(!empty($_GPC['listorder'])){
					foreach ($_GPC['displayorder'] as $id => $value) {
                    	pdo_update($table, array('listorder' => $value), array('id' => $id));
					}
					message('分类排序更新成功!', $this->createWebUrl('cate', array('op' => 'display')), 'success');

				}
			}
		
			$where="WHERE weid=".$_W['weid']." ";
			$pindex = max(1, intval($_GPC['page']));
			$psize = 20;
			$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($table) . $where);
			$start = ($pindex - 1) * $psize;
			$where .= "  order by `listorder` desc   LIMIT {$start},{$psize}";
	 	    $list = pdo_fetchall("SELECT * FROM ".tablename($table)." ".$where);
			$pager = pagination($total, $pindex, $psize);
		}		
        include $this->template('adv_cate');
	}

模板文件:

{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('cate', array('op' => 'post'))}">添加分类</a></li>
	<li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('cate', array('op' => 'display'))}">管理分类</a></li>
</ul>
{if $op == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form">
		<h4>分类详细设置</h4>
		<table class="tb">
			<tr>
				<th><label for="">排序</label></th>
				<td>
					<input type="text" name="listorder" class="span6" value="{$item['listorder']}" />
				</td>
			</tr>
                       
			<tr>
				<th><label for="">分类名称</label></th>
				<td>
					<input type="text" name="title" class="span6" value="{$item['title']}" />
				</td>
			</tr>
			<tr>
				<th><label for="">分类描述</label></th>
				<td>
					<textarea name="desc" class="span6" cols="70">{$item['desc']}</textarea>
				</td>
			</tr>
              
			<tr>
				<th></th>
				<td>
					<input name="submit" type="submit" value="提交" class="btn btn-primary span3">
					<input type="hidden" name="token" value="{$_W['token']}" />
				</td>
			</tr>
		</table>
	</form>
</div>

{elseif $op == 'display'}
<div class="main">
	<div class="category">
		<form action="" method="post" οnsubmit="return formcheck(this)">
		<table class="table table-hover">
			<thead>
				<tr>
					<th style="width:10px;"></th>
					<th style="width:60px;">显示顺序</th>
					<th>分类名称</th>
					<th style="width:80px;">操作</th>
				</tr>
			</thead>
			<tbody>
			{loop $list $row}
				<tr>
					<td>{$row['id']}</td>
					<td><input type="text" class="span1" name="listorder[{$row['id']}]" value="{$row['listorder']}"></td>
					<td>{$row['title']}</td>
					<td><a href="{php echo $this->createWebUrl('cate', array('op' => 'post', 'id' => $row['id']))}">编辑</a>  <a href="{php echo $this->createWebUrl('cate', array('op' => 'delete', 'id' => $row['id']))}" οnclick="return confirm('确认删除此分类吗?');return false;">删除</a></td>
				</tr>
				
			{/loop}
				<tr>
					<td></td>
					<td colspan="4">
						<a href="{php echo $this->createWebUrl('cate', array('op' => 'post'))}"><i class="icon-plus-sign-alt"></i> 添加新分类</a>
					</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="4">
						<input name="submit" type="submit" class="btn btn-primary" value="提交">
						<input type="hidden" name="token" value="{$_W['token']}" />
					</td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>
</div>
{/if}
{template 'common/footer'}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值