<?php
namespace Home\Controller;
use Common\Controller\BaseController;

class NewsController extends BaseController{
	
	
	public function  index(){
	
	$data=D('NoticeType')->order('paixi asc')->select();
	$id=I('get.type');

	if(I('get.type')!=""){$map['type']=I('get.type');}
	
	$count = D('Notice')->where($map)->count();// 查询满足要求的总记录数
	$Page = new \Think\Page($count,C('PAGE_NUM'));// 实例化分页类 
	$show = $Page->show();// 分页显示输出
	$list=D('Notice')->where($map)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
	
	
	
	$assign=array(
	'data'=>$data,
	'list'=>$list,
	'page'=>$show,
	'id'=>$id,
	);
	$this->assign($assign);
    $this->display();
    }
	
	/*
	文章内容展示
	*/
	
	public function  view(){
	$where['id']=I('get.id');
	$view=D('Notice')->where($where)->find();	
	$view['content']=htmlspecialchars_decode($view['content']);	
	$id=$view['type'];//当前文章的分类ID
	$data=D('NoticeType')->order('paixi asc')->select();
	
	$assign=array(
	'data'=>$data,
	'view'=>$view,
	'id'=>$id,
	);	
	$this->assign($assign);
	$this->display();	
	}	
	
	/*查询顶级分类的ID
	AUTHOR  Musto   www.ew80.com
	*/
	protected  function  getpid($id=0){
	global $pid;
	$tj['id']=array('eq',$id);
	$rs=D('HelpType')->where($tj)->find();
	if($rs['pid']!='0'){
	$id=$rs['pid'];
	$this->getpid($id);
	}else{
	$pid=$rs['id'];
	}
	return  $pid;
	
	}
	
	/*
	获取所有子类ID列表
	*/
	protected function getAllChildcateIds($categoryID)
    {
        //初始化ID数组
        $array[] = $categoryID;
        do
        {
            $ids = '';
            $where['pid'] = array('in',$categoryID);
            $cate = D('HelpType')->where($where)->select();
            foreach ($cate as $k=>$v)
            {
                $array[] = $v['id'];
                $ids .= ',' . $v['id'];
            }
            $ids = substr($ids, 1, strlen($ids));
            $categoryID = $ids;
        }
        while (!empty($cate));
        $ids = implode(',', $array);
        return $ids;    //  返回字符串
        //return $array //返回数组
    }
	
	
	
	

}