本文整理汇总了PHP中app\models\Post::link方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::link方法的具体用法?PHP Post::link怎么用?PHP Post::link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::link方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
/** @var Category[] $categories */
$categories = Category::find()->where(['id' => $model->categories_id])->all();
foreach ($categories as $category) {
$model->link('categories', $category);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'category_names' => ArrayHelper::map(Category::find()->all(), 'id', 'name')]);
}
}
示例2: actionNew
public function actionNew()
{
$postModel = new Post();
$category = new Category();
$categoryList = ArrayHelper::map($category->find()->asArray()->all(), 'id', 'title');
$postList = $postModel->find()->asArray()->all();
$message = '';
if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
$selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
foreach ($selectedCategories as $category) {
$postModel->link('categories', $category);
}
$message = 'Category added success';
}
return $this->render('new', ['model' => $postModel, 'message' => $message, 'categoryList' => $categoryList, 'postList' => $postList]);
}
示例3: actionEdit
public function actionEdit($id)
{
$model = Moderation::findOne((int) $id);
if (!$model) {
throw new Exception("Запись не найдена!");
}
if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post(), $model->formName()) && $model->validate() && !Yii::$app->request->post('nosave', false)) {
$post = new Post();
$post->attributes = $model->attributes;
$post->visible = true;
$tags = Yii::$app->request->post($model->formName(), ['tags' => []])['tags'];
if ($post->save()) {
if (!empty($tags)) {
foreach ($tags as $tag) {
$modelTag = Tag::add($tag);
if ($modelTag) {
$post->link('tags', $modelTag);
}
}
}
$model->delete();
// публикация в твиттере
ContentGenerator::Twitter($post);
return $this->redirect('moderate');
}
}
return $this->render('_edit', ['model' => $model]);
}