本文整理汇总了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);
}
}
}
}