Using Yii2 I'll need to provide a DataProvider with specific data.
The problem is that I need to create a single DataProvider with an array data and data from a table in a database.
Therefore, I think that I should mix an ArrayDataProvider and an ActiveDataProvider. I don't know if Yii2 offers tools for this situations or should I create my own DataProvider from BaseDataProvider.
I cant post some code because is a knowledge question.
According to your description, you could try to get the data from the DB as an Array, then merge it with the other array you have, and then put it all in an ArrayDataProvider
Try this (not tested):
$dbData = Model::find()->all(); //load your data from DB
$arrayData = [...]; //your other data as an array
// do the merge, with ArrayHelper::merge() or somehow manually
$data = ArrayHelper::merge($dbData, $arrayData);
$provider = new ArrayDataProvider([
'allModels' => $data
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With