How to save Dropdownlist and Checkboxlist in Yii2
I created a Checkboxlist as shown below:
I want the user to be able to select the dependent dropdownlist and check any of the checkbox for subjects.
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
View
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
The error is as shown below in the screenshots:
I have these question:
1. Why am I getting this error
uninitialized string offset: 1
it saves only 2 rows
the checkall for the checkboxlist is not working
How do I show a dialog box if the user does not select any checkbox?
javascript yii2
add a comment |
I created a Checkboxlist as shown below:
I want the user to be able to select the dependent dropdownlist and check any of the checkbox for subjects.
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
View
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
The error is as shown below in the screenshots:
I have these question:
1. Why am I getting this error
uninitialized string offset: 1
it saves only 2 rows
the checkall for the checkboxlist is not working
How do I show a dialog box if the user does not select any checkbox?
javascript yii2
Using thisisNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using$model = new AcaClassSubjects();
inside the for loop to insert multiple.
– Muhammad Omer Aslam
Nov 19 '18 at 18:11
1
and what's with$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you canYii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it
– Muhammad Omer Aslam
Nov 19 '18 at 18:14
add a comment |
I created a Checkboxlist as shown below:
I want the user to be able to select the dependent dropdownlist and check any of the checkbox for subjects.
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
View
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
The error is as shown below in the screenshots:
I have these question:
1. Why am I getting this error
uninitialized string offset: 1
it saves only 2 rows
the checkall for the checkboxlist is not working
How do I show a dialog box if the user does not select any checkbox?
javascript yii2
I created a Checkboxlist as shown below:
I want the user to be able to select the dependent dropdownlist and check any of the checkbox for subjects.
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
View
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
The error is as shown below in the screenshots:
I have these question:
1. Why am I getting this error
uninitialized string offset: 1
it saves only 2 rows
the checkall for the checkboxlist is not working
How do I show a dialog box if the user does not select any checkbox?
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
public function actionCreate()
{
$model = new AcaClassSubjects();
if ($model->load(Yii::$app->request->post()) && isset($_POST['AcaClassSubjects'])) {
$model->attributes = $_POST['AcaClassSubjects'];
for($i=0;$i<count($_REQUEST['AcaClassSubjects']['class_subject_subject_id']);$i++) :
$model->class_subject_id = NULL;
$model->isNewRecord = true;
$model->class_subject_subject_id = $_POST['AcaClassSubjects']['class_subject_subject_id'][$i];
$model->class_subject_class_group_id = $_POST['AcaClassSubjects']['class_subject_class_group_id'];
$model->class_subject_class_id = $_POST['AcaClassSubjects']['class_subject_class_id'];
$model->created_by = Yii::$app->getid->getId();
$model->created_at = new yiidbExpression('NOW()');
if($model->save()) {
Yii::$app->session->setFlash('green-'.$i, '<i class="fa fa-info-circle"></i> <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' for <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' is created successfully');
} else {
Yii::$app->session->setFlash('red-'.$i, '<i class="fa fa-warning"></i> The combination of <b>Class:</b> '.AcaClassMaster::findOne($_POST['AcaClassSubjects']['class_subject_class_id'])->class_name.' and <b>Subject: </b>'.AcaSubjects::findOne($_POST['AcaClassSubjects']['class_subject_class_id'][$i])->subject_name.' has already been taken.');
}
endfor;
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
<div class="col-xs-12 col-lg-12">
<div class="<?php echo $model->isNewRecord ? 'box-success' : 'box-info'; ?> box view-item col-xs-12 col-lg-12">
<div class="academic-subject-form">
<?php $form = ActiveForm::begin([
'id' => 'academic-subject-form',
'enableAjaxValidation' => false,
'fieldConfig' => [
'template' => "{label}{input}{error}",
],
]); ?>
<div class="col-xs-12 col-lg-12 no-padding">
<div id="root-container-id" class="col-xs-12 col-sm-12 col-lg-12">
<?=
$form->field($model, 'class_subject_subject_id')->checkboxList(AcaSubjects::forWidget(),[
'item' => function($index, $label, $name, $checked, $value) {
$checked = $checked ? 'checked' : '';
//'class' => 'check-all';
return "<label class='checkbox col-md-4' style='font-weight: normal;'><input type='checkbox' {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
])->label('Subjects <label><input type="checkbox" id="root-container-id">Check All</label>');
?>
</div>
</div>
<div class="form-group col-xs-12 col-sm-6 col-lg-4 no-padding">
<div class="col-xs-6">
<?= Html::submitButton($model->isNewRecord ? Yii::t('aca', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-block btn-success' : 'btn btn-block btn-info']) ?>
</div>
<div class="col-xs-6">
<?= Html::a(Yii::t('academic', 'Cancel'), ['index'], ['class' => 'btn btn-default btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
javascript yii2
javascript yii2
edited Nov 19 '18 at 17:02
chazsolo
5,2701233
5,2701233
asked Nov 19 '18 at 16:49
M.O. IdowuM.O. Idowu
947
947
Using thisisNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using$model = new AcaClassSubjects();
inside the for loop to insert multiple.
– Muhammad Omer Aslam
Nov 19 '18 at 18:11
1
and what's with$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you canYii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it
– Muhammad Omer Aslam
Nov 19 '18 at 18:14
add a comment |
Using thisisNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using$model = new AcaClassSubjects();
inside the for loop to insert multiple.
– Muhammad Omer Aslam
Nov 19 '18 at 18:11
1
and what's with$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you canYii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it
– Muhammad Omer Aslam
Nov 19 '18 at 18:14
Using this
isNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using $model = new AcaClassSubjects();
inside the for loop to insert multiple.– Muhammad Omer Aslam
Nov 19 '18 at 18:11
Using this
isNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using $model = new AcaClassSubjects();
inside the for loop to insert multiple.– Muhammad Omer Aslam
Nov 19 '18 at 18:11
1
1
and what's with
$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you can Yii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it– Muhammad Omer Aslam
Nov 19 '18 at 18:14
and what's with
$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you can Yii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it– Muhammad Omer Aslam
Nov 19 '18 at 18:14
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379247%2fhow-to-save-dropdownlist-and-checkboxlist-in-yii2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379247%2fhow-to-save-dropdownlist-and-checkboxlist-in-yii2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Using this
isNewRecord=true
is to be done in rare use cases and not something to promote as a default practice. Developers should not use this for the example in this issue as the framework's architecture is not designed for this use-case. see comment , try using$model = new AcaClassSubjects();
inside the for loop to insert multiple.– Muhammad Omer Aslam
Nov 19 '18 at 18:11
1
and what's with
$_REQUEST['AcaClassSubjects']['class_subject_subject_id']
why you are using it when you canYii::$app->request->post('AcaClassSubjects')['class_subject_subject_id']
, use the framework power when you are working in it– Muhammad Omer Aslam
Nov 19 '18 at 18:14