當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::getAsset方法代碼示例

本文整理匯總了PHP中common\models\Post::getAsset方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::getAsset方法的具體用法?PHP Post::getAsset怎麽用?PHP Post::getAsset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Post的用法示例。


在下文中一共展示了Post::getAsset方法的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'));
 }
開發者ID:alexsynytskiy,項目名稱:Dynamomania,代碼行數:37,代碼來源:SiteController.php


注:本文中的common\models\Post::getAsset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。