本文整理汇总了PHP中common\models\Post::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::hasAttribute方法的具体用法?PHP Post::hasAttribute怎么用?PHP Post::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Post
的用法示例。
在下文中一共展示了Post::hasAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSocialRss
/**
* Url: /yandex|vk|tw|fb/rss.xml
* @param $kind
* @return string
* @throws NotFoundHttpException
*/
public function actionSocialRss($kind)
{
$kind = 'is_' . $kind . '_rss';
$post = new Post();
if (!$post->hasAttribute($kind)) {
throw new NotFoundHttpException('Страница не найдена.');
}
Yii::$app->response->format = Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'text/xml; charset=utf-8');
$posts = Post::find()->where(['is_public' => 1, $kind => 1])->orderBy(['created_at' => SORT_DESC])->limit(50)->all();
$items = [];
foreach ($posts as $post) {
$content = $post->getShortContent(500, 700);
$fulltext = strip_tags($post->content, '<p><a><br>');
$authorName = isset($post->user) ? $post->user->getDisplayName() : false;
$image = $post->getAsset(Asset::THUMBNAIL_CONTENT);
$enclosureUrl = file_exists($image->getFilePath()) ? $image->getFileUrl() : false;
$enclosureType = $enclosureUrl ? image_type_to_mime_type(exif_imagetype($image->getFilePath())) : false;
$item = ['title' => htmlspecialchars($post->title), 'link' => $post->url, 'description' => htmlspecialchars($content), 'fulltext' => htmlspecialchars($fulltext), 'pubDate' => date('r', strtotime($post->created_at)), 'authorName' => $authorName, 'enclosureUrl' => $enclosureUrl, 'enclosureType' => $enclosureType];
$items[] = (object) $item;
}
$title = 'Динамомания: Новости';
$description = 'Лента последних новостей';
if ($kind == 'is_yandex_rss') {
$view = '@frontend/views/site/yandex_rss';
} else {
$view = '@frontend/views/site/rss';
}
return $this->renderPartial($view, compact('title', 'description', 'items'));
}