CDcriteria in yii2

I am following blog guide for yii1 and I am trying to recreate everything with yii2.

I am stuck with addTags method of Tag model. I do not know how to convert this code to yii2. Can some1 help me please ?




public function addTags($tags)

{

    $criteria = new CDbCriteria;

    $criteria->addInCondition('name', $tags);

    $this->updateCounters(array('frequency' => 1), $criteria);

    

    foreach($tags as $name){

        if(!$this->exists('name=:name', array(':name' => $name))){

            $tag = new Tag;

            $tag->name = $name;

            $tag->frequency = 1;

            $tag->save();

        }

    }

}



I am confused with this addInCondition, there is no such thing in yii2 as well as CDbCriteria. How to make this work in yii2 ?

I still cant find solution. Whatever I do it doesnt work. Can any1 help pls ?


$this->updateCounters(['frequency' => 1]);

This gives me error: Using $this when not in object context. Why ? In Yii 1 everything works fine.

$this object is not available. You should/could use the $model instead.

If you need further help please post your full code not only fragments.

http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#updateCounters()-detail