<?php
namespace Home\Controller;

class SearchController extends BaseController {
    function index(){
		$key = I('k');
		$this->content = array('title'=>$key);
		//列表
		$db = M('content');
		$shownum = F('ArticleShowNum');
		$page = isset($_GET['p']) ? $_GET['p'] : 1;
		$count         = $db->where(array('title'=>array('LIKE','%'.$key.'%'),'keyword'=>array('LIKE','%'.$key.'%'),'_logic'=>'OR'))->count();
		if($count == 0){
			$this->category = NULL;
			$this->display();
			exit;
		}
		$Page          = new \Think\Page($count,$shownum);
		$Page->url     = '/search?key='.$key.'&p='.urlencode('[PAGE]');
		$this->page    = $Page->show();
		$this->category    = $db->where(array('title'=>array('LIKE','%'.$key.'%'),'keyword'=>array('LIKE','%'.$key.'%'),'_logic'=>'OR'))->order('ord desc, id desc')->page($page.','.$shownum)->select();
		$this->display();
    }
}