How to send value from model to modelSearch

Hi i want to send $tipo_empresa value from model to modelSearch to personalize search function but i can’t do it

Hope you can you help

Warm Regards

In ContactController.php




public function actionIniciativaPrivada()

    {

        $tipo_empresa = 1; // I need to send this value to ContactSearch.php

        $searchModel = new ContactosSearch();

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('iniciativa-privada', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }



In ContactSearch.php




 public function search($params)

    {

        $query = Contactos::find();


        $query->joinWith('cuenta');

        $query->where('tipocuenta_id = ' . $tipo_empresa );  // This value is from ContactController

        

      ... 

    }




In ContactController.php




public function actionIniciativaPrivada()

    {

        // $tipo_empresa = 1; // I need to send this value to ContactSearch.php

        $searchModel = new ContactosSearch();

        $searchModel->tipocuenta_id = 1; // this is it

        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);


        return $this->render('iniciativa-privada', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }



In ContactSearch.php




 public function search($params)

    {

        $query = Contactos::find();


        $query->joinWith('cuenta');

        // Probably you don't need to write this ...

        $query->where('tipocuenta_id = ' . $this->tipocuenta_id );

        // gii has already created something like this 

        $query->andFilterWhere(['tipocurenta_id' => $this->tipocuenta_id]);

      ... 

    }




Note that a search model is meant to be a container of the search parameters.

Thanks perfect, is working now

Warm Regards