/**
  * 首页
  *
  */
 public function actionIndex()
 {
     $model = new Soft();
     $criteria = new CDbCriteria();
     $condition = "type = " . $this->_type;
     $title = trim($this->_request->getParam('title'));
     $catalogId = intval($this->_request->getParam('catalogId'));
     $title && ($condition .= ' AND title LIKE \'%' . $title . '%\'');
     $catalogId && ($condition .= ' AND catalog_id= ' . $catalogId);
     $criteria->condition = $condition;
     $criteria->order = 't.id DESC';
     $criteria->with = array('catalog');
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     //根据title,catelogId查询
     $pageParams = $this->buildCondition($_GET, array('title', 'catalogId'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     //推荐位
     $recom_list = RecommendPosition::model()->findAll('type=:type', array(':type' => $this->_type));
     $this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'recom_list' => $recom_list));
 }
Esempio n. 2
0
 public function run()
 {
     $model = new Soft();
     //条件
     $criteria = new CDbCriteria();
     $title = trim(Yii::app()->request->getParam('title'));
     $catalogId = intval(Yii::app()->request->getParam('catalogId'));
     $criteria->addColumnCondition(array('type' => $this->controller->_type));
     $title && $criteria->addSearchCondition('title', $title);
     $catalogId && $criteria->addColumnCondition(array('catalog_id' => $catalogId));
     $criteria->order = 't.id DESC';
     $criteria->with = array('catalog');
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 10;
     $pages->applyLimit($criteria);
     $result = $model->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
 }
 public function testSoftDelete()
 {
     Soft::create(array('name' => 'John Doe'));
     Soft::create(array('name' => 'Jane Doe'));
     $this->assertEquals(2, Soft::count());
     $user = Soft::where('name', 'John Doe')->first();
     $this->assertEquals(true, $user->exists);
     $this->assertEquals(false, $user->trashed());
     $this->assertNull($user->deleted_at);
     $user->delete();
     $this->assertEquals(true, $user->trashed());
     $this->assertNotNull($user->deleted_at);
     $user = Soft::where('name', 'John Doe')->first();
     $this->assertNull($user);
     $this->assertEquals(1, Soft::count());
     $this->assertEquals(2, Soft::withTrashed()->count());
     $user = Soft::withTrashed()->where('name', 'John Doe')->first();
     $this->assertNotNull($user);
     $this->assertInstanceOf('Carbon\\Carbon', $user->deleted_at);
     $this->assertEquals(true, $user->trashed());
     $user->restore();
     $this->assertEquals(2, Soft::count());
 }