I created a list in view by iterating items in an session array over a loop. I even put check boxes for each iteration. I need to get the checked values as a string or an array of strings in to controller. How can I do that. This is the view part.
<?php
$session = Yii::$app->session;
$array = explode('\r\n', $session['cdr_val']) ;
?>
<div class="box-header with-border">
<h3 class="box-title">CDR Configurations</h3>
<?= Html::a('<span class="glyphicon pull-right glyphicon-transfer"></span>', ['#'], ['data-url' => Url::toRoute(['cdr/compare']), 'id' => 'btn-compare', 'title' => 'Compare']); ?>
</div>
<div class="box-body">
<!--form class="form-horizontal" name="form_blacklist_table" id=""-->
<div class="row">
<div class="box-body boxpad contSeperator">
<div class="col-md-12 col-sm-12 col-xs-12">
<table id="analyse-table" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th class="actions-fix-wd-1 text-center">Select</th>
<th>CDR</th>
<th class="actions-fix-wd-2 text-center">Action</th>
</tr>
</thead>
<tbody>
<?php if ($array[0]!=''){ ?>
<?php $j = 0 ?>
<?php do{ ?>
<tr>
<td class="text-center">
<!--?=
//$form->field($model, 'status')->checkbox(['value' => "$j",'encode'=>false,'label'=>null]) ?-->
<input name="checkbox1" id="checkbox1" type="checkbox" value="<?= $j ?>">
</td>
<td>
<div>
<?php
echo($array["$j"]);
?>
</div>
</td>
<td class="text-center actions">
<?= Html::a('<span class="glyphicon glyphicon-check"></span>', ['#'], ['data-url' => Url::toRoute(['cdr/analyze','id'=>$array["$j"]]), 'id' => 'btn-view', 'title' => 'analyze']); ?>
</td>
<?php $j++ ?>
</tr>
<?php }while($j<sizeof($array)); ?>
<?php } ?>
And i used javascript part to trigger the checkboxes, And it successsfully triggered the checkbox checked values. but i couldn't any way to send it to controller.
$urlView1 = Url::to('cdr/compare');
$script1 = <<< JS
$( document ).ready(function() {
$(document).on('click', '#btn-compare', function(e) {
var items=document.getElementsByName('checkbox1');
var selectedItems="";
for(var i=0;i<items.length;i++){
if(items[i].type=='checkbox' && items[i].checked==true){
selectedItems+=","+items[i].value;
}
}
//console.log("{$urlView1}")
/*$.ajax({
url : "http://localhost:8080/index.php?r=cdr/compare",
type : 'post',
data: 'items=' + selectedItems,
success : function(data){
console.log(data);
$('#view-comp').attr("src", $(this).attr('data-url'));
$('#ViewModal').modal({show:true})
var data = JSON.parse(data);
},
});*/
$('#view-comp').attr("src", $(this).attr('data-url'));
$('#ViewComp').modal({show:true})
return false;
});
});
JS;
$this->registerJs($script1);
here is the necessary controller part
public function actionCompare(){
$model = new CdrAllinone();
$session = Yii::$app->session;
$this->layout = 'popup';
print_r(Yii::$app->request->getUrl());
print_r($_POST);
And model has the variables defined and returned.
getmethod in request.