public function actionIndex() { $id = $_REQUEST['category_id']; $price = $_REQUEST['price']; $category = Category::model()->findByPk($id); if ($id) { $catmodel = new Category(); $ids = $catmodel->getMeChildsId($id); $cid = implode(',', $ids); $condition = $id ? 'is_show = 1 and category_id in (' . $cid . ')' : 'is_show = 1'; } if ($price) { if ($price && $id) { $catmodel = new Category(); $ids = $catmodel->getMeChildsId($id); $cid = implode(',', $ids); $condition = $id ? 'is_show = 1 and shop_price=' . $price . ' and category_id in (' . $cid . ')' : 'is_show = 1'; } } $keyword = $_REQUEST['keyword']; if ($keyword) { $condition = $keyword ? 'is_show = 1 and title like' . "'%{$keyword}%'" . 'or sn like' . "'%{$keyword}%'" : 'is_show = 1'; } $criteria = new CDbCriteria(array('condition' => $condition, 'order' => 'sort_order asc, item_id desc')); $count = Item::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 20; $pages->applyLimit($criteria); $items = Item::model()->findAll($criteria); $this->render('index', array('items' => $items, 'pages' => $pages, 'keyword' => $keyword, 'category' => $category)); }