我在yii2高级模板项目中创建rss时遇到问题。我尝试通过在composer.json中添加必要的代码来在我的项目中安装zelenin rss扩展,但是当我尝试使用它时,会出现错误:Class' Zelenin \ yii \ extensions \ Rss \ RssView&#39 ;未找到 我相信错误来自从链接获取的控制器功能。 这是代码:
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);
}
]
]);
我已遵循git hub链接(https://github.com/zelenin/yii2-rss)中的指南,但仍然无法使用它。
我已经尝试了好几个小时。谁能告诉我一个正确的方法来实现我的网站的RSS功能? 谢谢。
答案 0 :(得分:0)
尝试添加
<div id="a2Nb000000035ohEAA" class="collapse DisciplineDetails PassportDetails PermDesc">
<h3 class="PermissionsListHeader">Advising on a home purchase plan</h3>
<br>
<br>
</div>
<ul class="PermissionConditionsList">
<li class="PermissionsConditionsItem">
Customer Type
<ul class="PermCondsLimitationsList">
<li style="list-style: none"><span id="j_id0:j_id1:j_id110:regActTable:0:j_id531:0:j_id533:0:j_id535:0:j_id538"></span></li>
<li class="PermCondsLimitationsItem Popover">Customer</li>
</ul>
</li>
</ul>
<ul class="PermissionConditionsList">
<li class="PermissionsConditionsItem">
Investment Type
<ul class="PermCondsLimitationsList">
<li style="list-style: none"><span id="j_id0:j_id1:j_id110:regActTable:0:j_id531:1:j_id533:0:j_id535:0:j_id538"></span></li>
<li class="PermCondsLimitationsItem Popover">Home purchase plans</li>
</ul>
</li>
</ul>
</div>
到您的控制器