本文整理汇总了PHP中app\models\Tag::eliminateOrphans方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::eliminateOrphans方法的具体用法?PHP Tag::eliminateOrphans怎么用?PHP Tag::eliminateOrphans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Tag
的用法示例。
在下文中一共展示了Tag::eliminateOrphans方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSaveNotes
/**
* Saves notes passed in Json and returns updated notes as Json
* @return Array of objects
*/
public function actionSaveNotes()
{
$saved = false;
$this->_setJsonResponse();
if (!Yii::$app->request->getIsPost()) {
throw new NoteControllerInvalidCallException('Invalid call... ' . __METHOD__ . ' takes in only POST requests.');
}
$noteData = Json::decode(Yii::$app->request->getPost('notes'));
foreach ($noteData as $data) {
$note = Note::find($data['id']);
if (is_null($note)) {
$note = new Note();
}
$changed = $note->saveUpdateable($data);
if ($changed) {
$saved = true;
}
}
# If there were db changes we want to remove any leftover tags...
if ($saved) {
Tag::eliminateOrphans();
}
# Tags
$tagData = Json::decode(Yii::$app->request->getPost('tags'));
$tags = Tag::getAll(true);
# Get tag data as array
# Map Tag statuses
if (count($tagData) > 0) {
Tag::mapStatuses($tags, $tagData);
}
# Reload Note's array
$notes = Note::getAll(true);
# Reorder Note array
Note::reorder($notes, $noteData);
return array('notes' => $notes, 'tags' => $tags);
}