当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::link方法代码示例

本文整理汇总了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')]);
     }
 }
开发者ID:viktornord,项目名称:gh-php-hackaton-basic,代码行数:19,代码来源:PostController.php

示例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]);
 }
开发者ID:stanislavdev1993,项目名称:blog,代码行数:16,代码来源:PostController.php

示例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]);
 }
开发者ID:mamontovdmitriy,项目名称:aaaaa,代码行数:28,代码来源:SiteController.php


注:本文中的app\models\Post::link方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。