Yii2 dropdownlist

Asked

Viewed 413 times

1

I need an example, dropdownlist, where I can dropdown between two sqls, in this case A and B.

Below I present a pseudocode.

Introduction to the problem:

Table sql A

id_A
id_usuario
nome_A
descricao_A

Table sql B

id_B
id_A
nome_B
descricao_B

I need to dropdown with sql B, where all fields of sql A that have the id_usuario = 10, but in sql B I do not have the id_usuario field, you should have something like Inner Join, but using yii2 dropdownlist.

The syntax below, which I am using does not solve, because it only presents the fields that satisfies id_A (sql A and B).

dropDownList(\yii\helpers\ArrayHelper::map(B::find()->where(['id_A' => $A->id_A])->all(),'id_B','nome_B') ,

P.S. I don’t want to put id_usuario in sql B.

1 answer

0


I found the solution, in the above example just perform the following modification:

$id_usuario = Yii::$app->user->identity->getId();

dropDownList(\yii\helpers\ArrayHelper::map(B::find()->([A])->where(['id_usuario' => $id_usuario])->all(),'id_B','nome_B') 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.