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