Answer the question
In order to leave comments, you need to log in
How to merge two ActiveDataProvider yii2 instances?
Hello. There are two entities: News and Articles. Displayed on different pages using ActiveDataProvider.
How do I combine them for use in a common list on the same page in a single ActiveDataProvider?
$dataProvider = new ActiveDataProvider([
'query' => News::find(),
]);
$dataProvider2 = new ActiveDataProvider([
'query' => Articles::find(),
]);
Answer the question
In order to leave comments, you need to log in
Good morning.
Is there any connection between articles and news? Why do you need to do it this way?
Explain what you want to achieve?
And there may be several solutions.
If there is some kind of connection between them, then it can be done through a connection or through a union of queries or through a join or something else, but how exactly - it will be clear only after your detailed explanation.
PS
You can try to change your code like this:
function actionTag($tag)
{
$dataProvider = new ActiveDataProvider([
'query' => News::find()->anyTagValues($tag)->where(['status' => News::STATUS_ACTIVE]),
]);
$query2 = (new \yii\db\Query())
->from('articles');
$query->union($query2);
return $this->render('tag', [
'dataProvider' => $dataProvider,
'tag' => $tag,
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question