如下圖:服務管理和資源回收筒要顯示不同的清單資料,但是樣式基本相同,就不用寫兩個頁面了,隻需要在頁面跳轉的時候攜帶不同參數,查詢相對應的資料,對樣式的不同之處判斷顯示即可
這是跳轉頁面的代碼:我攜帶的參數分别是"all"和"deleted" (選中樣式也要判斷)
<li class="<?php echo $cate == 'all' ? 'active':'' ; ?>"><a href="{:U('Business/index',array('cate'=>'all'))}" target="_blank" rel="external nofollow" >服務管理</a></li>
<li><a href="{:U('Business/add')}" target="_blank" rel="external nofollow" target="_self">添加服務</a></li>
<li class="<?php echo $cate == 'deleted' ? 'active':'' ; ?>"><a href="{:U('Business/index',array('cate'=>'deleted'))}" target="_blank" rel="external nofollow" target="_self">資源回收筒</a></li>
部分的标簽“服務管理”需要,但是“資源回收筒”不需要,是以先給一個樣式
<style>
.hidden{
display: none;
}
</style>
根據控制器裡傳過來的參數判斷需不需要顯示(這裡是“一鍵上架”,“一鍵下架”,“删除”按鈕的顯示)
<button class="<?php echo $cate == 'deleted' ? 'hidden':'' ; ?> btn btn-primary btn-small js-ajax-submit" type="submit" data-action="{:U('Business/top',array('top'=>1))}" data-subcheck="true">一鍵上架</button>
<button class="<?php echo $cate == 'deleted' ? 'hidden':'' ; ?> btn btn-primary btn-small js-ajax-submit" type="submit" data-action="{:U('Business/top',array('untop'=>1))}" data-subcheck="true">一鍵下架</button>
<button class="<?php echo $cate == 'deleted' ? 'hidden':'' ; ?> btn btn-danger btn-small js-ajax-submit" type="submit" data-action="{:U('Business/delete')}" data-subcheck="true" data-msg="您确定删除嗎?">删除</button>
<!-- a标簽的判斷顯示 -->
<a href="{:U('Business/delete',array('id'=>$vo['id']))}" target="_blank" rel="external nofollow" >
<?php echo ($cate == "all") ? '| 删除':'' ?>
</a>
控制器代碼:
public function index()
{
//搜尋
$search_key = I('post.keyword', '');
if (!empty($search_key)) {
$where['title'] = ['like', '%' . $search_key . '%'];
}
//頁面傳過來的參數
$cate = I('get.cate/s','all');
if($cate == 'all'){
$where['delete_time'] = ['EQ', 0];
}else{
$where['delete_time'] = ['NEQ', 0];
}
$count = $this->business_item_model->where($where)->count();
$page = $this->page($count, 20);
$list = $this->business_item_model
->field('id,title,img,link,price,read_count,pay_count,is_show,`status`')
->where($where)
->order(['create_time' => 'desc'])
->limit($page->firstRow, $page->listRows)
->select();
foreach ($list as &$vo) {
$vo['img'] = sp_get_host() . C("TMPL_PARSE_STRING.__UPLOAD__") . $vo['img'];
}
$this->assign("list", $list);
$this->assign("cate", $cate);
$this->assign("search_key", $search_key);
$this->assign("page", $page->show("Admin"));
$this->display();
}