本文整理汇总了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;
}