<?php
namespace Admin\Controller;
use Think\Controller;

class PlabelController extends BasicController {

    public function pLabelList(){
    	$pLabel = M('plabel');
    	$p = I('get.p','1','htmlspecialchars');
    	$where = "is_del=0";
    	
    	$count = $pLabel->where($where)->count();// 查询满足要求的总记录数
    	$Page = new \Think\Page($count,20,$search_param);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    	$show  = $Page->show();// 分页显示输出
    	$labelList = $pLabel->field("plabel.id,name,count(program_label.pid) as count")->join("left join program_label on plabel.id=program_label.lid")->where($where)->group("plabel.id")->page($p.',20')->select();
    	$this->assign('labelList',$labelList);
    	$this->assign('page',$show);
    	$this->assign('roleid',session('role'));
		$this->assign('title','标签列表');
    	$this->display();
    }

	//删除标签
	public function delLabel(){
		$id = I('post.id','','htmlspecialchars');
		$pLabel = M('plabel');
		$programLabel = M('program_label');
		$data['is_del'] = 1;
		
		$pLabel->where("id='$id'")->save($data);
		$programLabel->where("lid='$id'")->delete();

		echo 1;
	}

}
