本文整理匯總了PHP中app\models\Post::loadModel方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::loadModel方法的具體用法?PHP Post::loadModel怎麽用?PHP Post::loadModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Post
的用法示例。
在下文中一共展示了Post::loadModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionShow
/**
* Shows post by it's ID
*
* @param $id
*
* @return string
* @throws \yii\web\NotFoundHttpException
*/
public function actionShow($id)
{
$post = Post::loadModel($id, false, false);
if ($post === null) {
throw new NotFoundHttpException();
}
return $this->render('show', ['model' => $post]);
}
示例2: actionSendPost
public function actionSendPost($postId)
{
/** @var \app\models\Post $post */
$post = Post::loadModel($postId);
if ($post === null) {
$this->stderr("Post {$postId} not found.");
return 1;
}
$emails = NewsletterSubscribers::find()->select('email, language_id')->groupBy('email')->asArray()->all();
$emails = ArrayHelper::map($emails, 'email', 'email', 'language_id');
$mailer = Yii::$app->mailer;
foreach ($emails as $language_id => $emailsList) {
/** @var Language $language */
$language = Language::findOne($language_id);
if ($language !== null && $post->hasTranslation($language_id)) {
Yii::$app->language = $language->yii_language;
foreach ($emailsList as $email) {
$message = $mailer->compose('new-post', ['language_id' => $language_id, 'post' => $post]);
$message->setFrom('amadablamorg@yandex.ru')->setTo($email)->setSubject(Yii::t('app', 'New post on Ama-Dablam.org'))->send();
}
}
}
return 0;
}