Reputation: 1
I have a problem while creating rss in my yii2 advance template project. I have try to install the zelenin rss extension in my project through adding necessary code in composer.json, but when i try to use it, there is an error: Class 'Zelenin\yii\extensions\Rss\RssView' not found I believe the error is from the controller function that taken from the link. Here is the code :
public function actionRss()
{
$searchModel = new EventOrganizerSearch();
$dataProvider = $searchModel->searchApprovedEvent();
$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' => function ($widget, \Zelenin\Feed $feed) {
$feed->addChannelTitle(Yii::$app->name);
},
'link' => Url::toRoute('/', true),
'description' => 'Posts ',
'language' => function ($widget, \Zelenin\Feed $feed) {
return Yii::$app->language;
},
'image'=> function ($widget, \Zelenin\Feed $feed) {
$feed->addChannelImage('http://example.com/channel.jpg', 'http://example.com', 88, 31, 'Image description');
},
],
'items' => [
'title' => function ($model, $widget, \Zelenin\Feed $feed) {
return $model->name;
},
'description' => function ($model, $widget, \Zelenin\Feed $feed) {
return StringHelper::truncateWords($model->content, 50);
},
'link' => function ($model, $widget, \Zelenin\Feed $feed) {
return Url::toRoute(['post/view', 'id' => $model->id], true);
},
'author' => function ($model, $widget, \Zelenin\Feed $feed) {
return $model->user->email . ' (' . $model->user->username . ')';
},
'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $model->updated_at);
return Url::toRoute(['post/view', 'id' => $model->id], true) . ' ' . $date->format(DATE_RSS);
},
'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $model->updated_at);
return $date->format(DATE_RSS);
}
]
]);
I have follow the guideline in the git hub link (https://github.com/zelenin/yii2-rss) but still fail to use it.
I have been trying for many hours. Can anyone show me a proper way to implement the rss features to my website? Thank you.
Upvotes: 0
Views: 773