本文整理汇总了PHP中common\models\Post::setMeta方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::setMeta方法的具体用法?PHP Post::setMeta怎么用?PHP Post::setMeta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Post
的用法示例。
在下文中一共展示了Post::setMeta方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'update' page.
*
* @param integer $post_type post_type_id
*
* @throws \yii\web\ForbiddenHttpException
* @throws \yii\web\NotFoundHttpException
* @return mixed
*/
public function actionCreate($post_type)
{
$model = new Post();
$postType = $this->findPostType($post_type);
$model->post_comment_status = Option::get('default_comment_status');
if (!Yii::$app->user->can($postType->post_type_permission)) {
throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
}
if ($model->load(Yii::$app->request->post())) {
$model->post_type = $postType->id;
$model->post_date = Yii::$app->formatter->asDatetime($model->post_date, 'php:Y-m-d H:i:s');
if ($model->save()) {
if ($termIds = Yii::$app->request->post('termIds')) {
foreach ($termIds as $termId) {
$termRelationship = new TermRelationship();
$termRelationship->setAttributes(['term_id' => $termId, 'post_id' => $model->id]);
if ($termRelationship->save() && ($term = $this->findTerm($termId))) {
$term->updateAttributes(['term_count' => $term->term_count++]);
}
}
}
if ($meta = Yii::$app->request->post('meta')) {
foreach ($meta as $meta_name => $meta_value) {
$model->setMeta($meta_name, $meta_value);
}
}
Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', '{post_type} successfully saved.', ['post_type' => $postType->post_type_sn]));
return $this->redirect(['update', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model, 'postType' => $postType]);
}