B
B
Binarix2015-08-27 07:06:31
Yii
Binarix, 2015-08-27 07:06:31

How to display related data in Yii2?

Tell me how to display related data in yii2? There are tables:
Posts with id, id_category, text
and Category fields with id_category, category fields.
I can query all the data from the Posts table, I do this:
$dataProvider = Posts::find()->all();
I can also make a selection in pure SQL, but I can’t find an example somewhere on how to do this with Yii2 operators.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Talgat Baltasov, 2015-08-27
@Binarix

In models relations are specified? If yes then you can
Posts::find()->with('category')->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question