<?php
class NewsAction extends HomeAction{
    public function _initialize() {
        parent::_initialize();
    }
	
	public function index(){
		$name = $this->getActionName();
        $action = D($name);
        $ary_get['pageall'] = $this->_get('pageall', 'htmlspecialchars', 10);
        $count = $action->where($where)->count();
        $obj_page = $this->_Page($count, $ary_get['pageall']);
        $page = $obj_page->newshow();
        $ary_data = $action->where($where)->limit($obj_page->firstRow, $obj_page->listRows)->order(array('order'=>'desc'))->select();
		
		$catlist=D('category')->where(array('model'=>$this->getActionName()))->select();
		$this->assign("catlist", $catlist);
        $this->assign("data", $ary_data);
        $this->assign("page", $page);
        $this->assign("filter",$ary_get);
        $this->display();		
	}	
    
    public function show(){
		$id=abs(intval($this->_request('id')));
		if(!$id){
			$this->error("非法访问");
		}
		$name = $this->getActionName();
		$datas = D($name)->where(array('id'=>$id))->find();
		$catarr=D('category')->where(array('id'=>$datas['cid']))->find();
		$this->assign("catarr",$catarr);		
		$this->assign("datas",$datas);
		$catlist=D('category')->where(array('model'=>$this->getActionName()))->select();
		$this->assign("catlist", $catlist);		
		$this->display();
    }
	
	public function lists(){
		$name = $this->getActionName();
        $action = D($name);
        $ary_get['pageall'] = $this->_get('pageall', 'htmlspecialchars', 10);
		
		$catid=abs(intval($this->_request('catid')));
		$where=array();
		if($catid){
			$where['cid']=$catid;	
			$catarr=D('category')->where(array('id'=>$catid))->find();
			$this->assign("catarr",$catarr);
		}
        $count = $action->where($where)->count();
        $obj_page = $this->_Page($count, $ary_get['pageall']);
        $page = $obj_page->newshow();
        $ary_data = $action->where($where)->limit($obj_page->firstRow, $obj_page->listRows)->order(array('order'=>'desc'))->select();
		
		$catlist=D('category')->where(array('model'=>$this->getActionName()))->select();
		$this->assign('catid',$catid);
		$this->assign("catlist", $catlist);		
        $this->assign("data", $ary_data);
        $this->assign("page", $page);
        $this->assign("filter",$ary_get);
        $this->display('index');		
	}
    
}