Ejemplo n.º 1
0
 /**
  * Lists all Posts models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostsSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->query->addOrderBy('date DESC');
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 2
0
 /**
  * Lists all Posts models.
  * @return mixed
  */
 public function actionIndex()
 {
     $model = new Posts();
     $arr = ['post_title' => 'Learning CodeIgniter', 'post_description' => 'CodeIgniter is framework php easy for new development', 'author_id' => 1];
     $model->insert('posts', $arr);
     echo 'successful';
     die;
     $searchModel = new PostsSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Ejemplo n.º 3
0
 public function actionRssCategory($category = NULL)
 {
     if (Yii::$app->params['enableRss']) {
         if ($category) {
             $dataProvider = new ActiveDataProvider(['query' => PostsSearch::find()->where(['published' => 1, 'slugUrl' => $category])->orderBy('created_at DESC')->join('INNER JOIN', "{{%sources}}", "sources_id=sources.id")->join('INNER JOIN', "{{%categories}}", "categories_id=categories.id"), 'pagination' => ['pageSize' => Yii::$app->params['pageSizeRss']]]);
             $response = Yii::$app->getResponse();
             $headers = $response->getHeaders();
             $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
             echo \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->params['SiteName'], 'link' => Url::toRoute('/', true), 'description' => Yii::t('app', 'New Records in category {0}', [Categories::getCategoryBySlug($category)->title]), 'language' => function ($widget, \Zelenin\Feed $feed) {
                 return Yii::$app->language;
             }], 'items' => ['image' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->activePhotos[0]->link;
             }, 'title' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return empty($model->title) || is_null($model->title) || !isset($model->title) ? $model->alternativeTitle : $model->title;
             }, 'description' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return '<img src="' . $model->activePhotos[0]->link . '" width="100" style="margin:10px;"/><br/>' . (!empty(StringHelper::truncateWords($model->content, 25)) ? StringHelper::truncateWords($model->content, 25) : NULL);
             }, 'link' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->urlFull;
             }, 'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->recordId . $model->updated_at;
             }, 'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return Date(DATE_RSS, $model->updated_at);
             }]]);
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }