Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionIndex() {
- $criteria = new CDbCriteria(array(
- 'alias' => 't',
- 'condition' => 't.status=' . Blog::STATUS_PUBLISHED,
- 'order' => 't.sticky DESC, t.create_time DESC',
- 'select'=>'t.id, title, url, teaser, status, create_time, update_time, author_id, counter, forum_id'
- ));
- if (isset($_GET['q'])) {
- $criteria->condition .= ' and (t.title LIKE :keyword or t.teaser LIKE :keyword or t.content LIKE :keyword)';
- $criteria->params = array(':keyword'=>'%'.strtr(strtolower($_GET['q']),array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%');
- }
- if (isset($_GET['tag'])) {
- $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';
- $criteria->condition .= ' and tbl_tag.name=:tag';
- $criteria->params = array(':tag'=>$_GET['tag']);
- }
- $dataProvider = new CActiveDataProvider('Blog', array(
- 'pagination' => array(
- 'pageSize' => Yii::app()->params['postsPerPage'],
- ),
- 'criteria' => $criteria,
- ));
- $this->render('index', array(
- 'dataProvider' => $dataProvider,
- ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement