本文整理汇总了PHP中app\models\Categories::getCategoryBySlug方法的典型用法代码示例。如果您正苦于以下问题:PHP Categories::getCategoryBySlug方法的具体用法?PHP Categories::getCategoryBySlug怎么用?PHP Categories::getCategoryBySlug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Categories
的用法示例。
在下文中一共展示了Categories::getCategoryBySlug方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionRssCategory
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.');
}
}