public function actionList($query) { \Yii::$app->response->format = Response::FORMAT_JSON; $items = []; $query = urldecode(mb_convert_encoding($query, "UTF-8")); foreach (Tag::find()->where(['like', 'name', $query])->asArray()->all() as $tag) { $items[] = ['name' => $tag['name']]; } return $items; }
public function beforeDelete() { $pks = []; foreach ($this->owner->tags as $tag) { $pks[] = $tag->primaryKey; } if (count($pks)) { Tag::updateAllCounters(['frequency' => -1], ['in', 'tag_id', $pks]); } Tag::deleteAll(['frequency' => 0]); TagIndex::deleteAll(['entity' => $this->getEntityClass(), 'entity_id' => $this->getEntityId()]); }