當前位置: 首頁>>代碼示例>>PHP>>正文


PHP News::link方法代碼示例

本文整理匯總了PHP中app\models\News::link方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::link方法的具體用法?PHP News::link怎麽用?PHP News::link使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\News的用法示例。


在下文中一共展示了News::link方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ImportNews

 private function ImportNews($array, $category)
 {
     foreach ($array as $item) {
         if (!$item['active']) {
             continue;
         }
         $save = false;
         $model = News::findOne($item['id']);
         // Checking is this ID free for use
         if ($model === null) {
             $save = true;
             $model = new News();
             $model->id = $item['id'];
         } else {
             // Asking user what he wants
             $question = 'News with the same id alredy exists in data base:' . PHP_EOL . 'Data from database:' . PHP_EOL . $this->NewsObjToSting($model) . 'New data from file:' . PHP_EOL . $this->NewsArrToString($item) . 'category_id = ' . $category->id . PHP_EOL;
             $this->stdout($question);
             $answer = $this->select('What you want to do?' . PHP_EOL . '(a - assign new id and save data, s - keep database data, d - keep id and save data)' . PHP_EOL, ['a' => 'assign new id and save data', 's' => 'keep database data', 'd' => 'keep id and save data']);
             switch ($answer) {
                 case 'a':
                     $model = new News();
                 case 'd':
                     $save = true;
                     break;
                 case 's':
                     break;
             }
         }
         // Saving data if it is needed
         if ($save) {
             $model->headline = $item['title'];
             $model->description = $item['description'];
             $model->date = $item['date'];
             $model->image = $item['image'];
             $model->content = $item['text'];
             $model->link('category', $category);
             $model->status = $item['active'] ? News::STATUS_ACTIVE : News::STATUS_INACTIVE;
             if ($model->save()) {
                 $this->stdout($this->NewsObjToSting($model) . 'saved sucesfully' . PHP_EOL);
             }
         }
     }
 }
開發者ID:Everus,項目名稱:idflyTest,代碼行數:43,代碼來源:ImportController.php


注:本文中的app\models\News::link方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。