My intention is to get deleted all rows of table,where checkbox is activated. Unfortunately, I didn’t find further informations about this. All i found is like this
Users may click on the checkboxes to select rows of the grid. The selected rows may be obtained by calling the following JavaScript code:
var keys = $('#grid').yiiGridView('getSelectedRows');
this won’t help me achieving my intention. So, I ask U,which components(MCV) are involved. Controller and View,as I assume -
class YourController extends Controller {
public function yourAction(){
/* get the selected rows */
$selection = (array)Yii::$app->request->post('selection');
foreach ($selection as $item) {
/* your code to do with the checked rows*/
}
}
[color="#1c2837"][size="2"]There is no explict context and it has been made by the Framework based on the function [/size][size="2"]$_POST[/size][/color][color="#111111"] of [/color][color="#1C2837"][size="2"].PHP.[/size][/color]
class Mail-eingangController extends Controller {
public function delete_records(){
/* get the selected rows */
$selection = (array)Yii::$app->request->post('selection');
foreach ($selection as $item) {
/* your code to do with the checked rows*/
}
}
And in Controller var_dump($selection) will show empty array,also after having selected all checkboxes. So,there is no context
public function actionDelete_records() {
$selection = (array) Yii::$app->request->post('selection');
var_dump($selection); //this will show empty array
foreach ($selection as $item) {
var_dump($item); //this will show nothing
}
}
Running this code shows up,that selection is in no context with my checkbox
if (null==((array)Yii::$app->request->post('selection'))) {
echo'There is not context between selection and ur checkBoxes...';
}
Ur solution will work. But it works only for one GridView. But I use two GridViews. Implementing two GridViewsl like this will prevent Controller doing its job
public function actionIndex() {
$searchModel = new MailEingangSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$searchModel_ausgang = new MailAusgangSearch();
$dataProvider_ausgang = $searchModel_ausgang->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'searchModel_ausgang' => $searchModel_ausgang,
'dataProvider' => $dataProvider,
'dataProvider_ausgang' => $dataProvider_ausgang
]);
}