I am struggling with getting data for user interface viewing and need some help to be pointed in the right direction.
The current goal at hand: - Create an excel like table from a large amount of db data oriented vertically with hover tips and conditional formatting. Oriented Vertically: IE, Table "Column Headers" are actually the first column instead of the first row.
I have chosen handsontable (javascript table utility) because of the flexible functionality. I have to convert PHP arrays to JSON per research. The table draws nicely, but for now I just want to get the data printed in my view. I’ll worry about handson later.
The current "task" at hand: Learning YII2 and getting the data I need from my models into the view! I want to do this the "Proper YII2" way as opposed to creating lots of loops manually to get through the model data. Maybe I do have to do that?
The current question: What are the differences on how a CRUD Search model works and standard db models? IE, one uses searchModel/dataProvider is not data and the other just returns a model.
I can populate data with GridView / CRUD with searchModel/dataProvider, but I just want access to the data. The searchModel/dataProvider just look like filters. Model can return an array of models, but I don’t know the proper way to access it. An array of models doesn’t appear to fit into Yii GridView or DetailView.
Controller w/ MODEL (validate only appears to work if model is not an array of objects, hence model[0]. ):
$date = date('md');
$model = \common\models\Gatewayevent::find()->where(['eventscheduleddate' => $date ])->all();
if($model[0]->validate()) {
return $this->render('index', ['model' => $model]);
} else
return $this->render('index');
View (DetailView doesn’t appear to work with an array of models):
DetailView::widget(['model' => $model, 'attributes' => ['eventheadendid','eventchannelid','eventfilename',],])
Controller w/ searchModel/dataProvider
$searchModel = new GatewayeventSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
View w/ searchModel (GridView appears to work with this fine):
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'eventheadendid',.....
....
Please suggest the best way to get db data into an array for JSON Encode -> Handsontable. Any help would be appreciated. I think I need to take a break, been playing/looking at code too long.