Where Is Cdbcriteria?

The line:

in my User.php model file generates the error:

What "use" statement do I need to write at the start of the file? I have tried many things but cannot find the right one.

Background: I am trying to use the playground code but am getting in a real pickle.

I have added this to the User.php model (the one that comes with the advanced template), which generates the error:

    public function search() {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('username', $this->username, true);

        $criteria->compare('email', $this->email, true);

        return new CActiveDataProvider(get_class($this), array(

            'criteria' => $criteria,

            'sort' => array(

                'defaultOrder' => 'username ASC',


            'pagination' => array(

                'pageSize' => 5




Also, what does this do? Is it a constructor that automatically calls the function ‘search’?

$model =new User('search');

I have to write:


$u = new User;

$model = $u->search();

Instead of

$model =new User('search');

otherwise I get the error:

I am new to PHP so please be patient with my understanding of :: \ and ->.

hello mtthwbrnd. you are trying to use yii1 classes in yii2. in yii2 there is no such a class named CDbCriteria. so download yii1 and then use. if you really want ti use yii2 then use ActiveQuery class. please read documentation before implementation.

You call ActiveDataProvider a bit differently in yii2.

$provider = new \yii\data\ActiveDataProvider([

    'query' => Post::find(),

    'pagination' => [

        'pageSize' => 20,



The [font="Courier New"]query[/font] parameter in ActiveDataProvider is an instance of \yii\db\ActiveQuery

You can read the query builder section of the docs to understand how to use this with various conditions/criteria.