Beispiel #1
0
 /**
  * Search action
  * @return string
  */
 public function actionSearch()
 {
     Url::remember('', 'search');
     $model = new SearchContent();
     if ($model->load(Yii::$app->request->get()) && $model->validate()) {
         if ($model->target == SearchContent::TARGET_WEB) {
             $dataProvider = $model->getItems();
             $this->layout = 'search-content';
             return $this->render('search', compact('model', 'dataProvider'));
         } else {
             return $this->redirect(Yii::$app->params['catalogSearchUrl'] . $model->q);
         }
     } else {
         return $this->redirect(Url::previous());
     }
 }
Beispiel #2
0
 public function actionRss()
 {
     $model = new SearchContent();
     $dataProvider = $model->getItems(true);
     $response = Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     /** @noinspection PhpUnusedParameterInspection */
     $response->content = RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => Yii::t('front', 'Articles'), 'language' => Yii::$app->language], 'items' => ['title' => function ($model, $widget) {
         return $model['title'];
     }, 'description' => function ($model, $widget) {
         return StringHelper::truncateWords($model['perex'], 50);
     }, 'link' => function ($model, $widget) {
         return Url::toRoute(['site/content', 'id' => $model['id']], true);
     }, 'guid' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model['updated_at']);
         return Url::toRoute(['site/content', 'id' => $model['id']], true) . ' ' . $date->format(DATE_RSS);
     }, 'pubDate' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model['updated_at']);
         return $date->format(DATE_RSS);
     }]]);
 }