當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。