<?php
class SearchAction extends IniAction{
    public function __construct() {
        parent::__construct();
    }
    public function index(){
        $keywords = I('post.keywords')?I('post.keywords'):I('get.keywords');
        if(!$keywords) $this->error ('请输入搜索的关键词');
        $where['title'] = array('like',"%{$keywords}%");
        $goodsdb = M('goods');
        $count = $goodsdb->where($where)->count();
        $once = 20;
        $Page = $this->iniPage($count,$once);
        $result = GoodsModel::I()->_getGoodsList($Page, $where);
        
        $totalPage = ceil($goodsdb->where($where)->count()/$once);
        $this->assign('goods',$result);
        $this->assign('keyword',$keywords);
        $this->assign('totalPage',$totalPage);
        if(IS_AJAX){
            $page = I('get.p','','intval');
            $this->assign('page',$page+1);
            $this->display('ajgetgoods');
        }else{
           $this->display(); 
        }
        
    }
}