Advertisement
Speeedfire

Untitled

Mar 9th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1.     public function actionIndex() {
  2.         $criteria = new CDbCriteria(array(
  3.                     'alias' => 't',
  4.                     'condition' => 't.status=' . Blog::STATUS_PUBLISHED,
  5.                     'order' => 't.sticky DESC, t.create_time DESC',
  6.                     'select'=>'t.id, title, url, teaser, status, create_time, update_time, author_id, counter, forum_id'
  7.         ));
  8.         if (isset($_GET['q'])) {
  9.             $criteria->condition .= ' and (t.title LIKE :keyword or t.teaser LIKE :keyword or t.content LIKE :keyword)';
  10.             $criteria->params = array(':keyword'=>'%'.strtr(strtolower($_GET['q']),array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%');
  11.         }
  12.        
  13.         if (isset($_GET['tag'])) {
  14.             $criteria->join .= ' right join tbl_blog_tags on t.id=tbl_blog_tags.blog_id right join tbl_tag on tbl_tag.id=tbl_blog_tags.tag_id';
  15.             $criteria->condition .= ' and tbl_tag.name=:tag';
  16.             $criteria->params = array(':tag'=>$_GET['tag']);
  17.         }
  18.                
  19.  
  20.         $dataProvider = new CActiveDataProvider('Blog', array(
  21.                     'pagination' => array(
  22.                         'pageSize' => Yii::app()->params['postsPerPage'],
  23.                     ),
  24.                     'criteria' => $criteria,
  25.         ));
  26.        
  27.         $this->render('index', array(
  28.             'dataProvider' => $dataProvider,
  29.         ));
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement