Answer the question
In order to leave comments, you need to log in
How to make table loading (multi loading) in Yii2?
I am using the latest demos.krajee.com/builder-details/tabular-form
module
.
<div class="panel-body">
<?php
$form = kartik\form\ActiveForm::begin(
[ 'id'=> $model->formName(),
]
);
echo TabularForm::widget([
// your data provider
'dataProvider' => $dataCertificate,
'form' => $form,
'staticOnly' => true,
'actionColumn' => false,
'attributes' => [
'certificate_code' => ['label' => 'certificate_code', 'type' => TabularForm::INPUT_HIDDEN_STATIC]
],
]);
?>
public function actionIndex() {
$model = new PackagesForm();
$certificates = Certificate::find()->where(['certificates.user_id' => Yii::$app->user->identity->id]);
$packages = Packages::find();
$dataProvider = new ActiveDataProvider([
'query' => $packages,
'sort' => [
'defaultOrder' => ['id' => SORT_DESC],
],
]);
$dataCertificate = new ActiveDataProvider([
'query' => $certificates,
'sort' => [
'defaultOrder' => ['id' => SORT_DESC],
],
]);
if (\yii\base\Model::loadMultiple($model, Yii::$app->request->post(), $formName = $model->formName()) && Model::validateMultiple($model)) {
$count = 0;
foreach ($models as $index => $model) {
// populate and save records for each model
if ($model->save()) {
$count++;
}
}
return $this->render('index', [
'model' => $model,
'certificates' => $certificates,
'dataProvider' => $dataProvider,
'dataCertificate' => $dataCertificate,
]);
} else {
var_dump(\yii\base\Model::loadMultiple($model, Yii::$app->request->post(), $formName = $model->formName()));
die();
return $this->render('index', [
'model' => $model,
'certificates' => $certificates,
'dataProvider' => $dataProvider,
'dataCertificate' => $dataCertificate,
]);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question