Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:modal_window [2018/05/31 15:58] smayr [Ad Hoc Modal] |
systems:yii2:modal_window [2018/05/31 16:04] (current) smayr [Modal Confirmation (called from GridView action)] |
||
---|---|---|---|
Line 76: | Line 76: | ||
yii\bootstrap\Modal:: | yii\bootstrap\Modal:: | ||
?> | ?> | ||
- | </ | ||
- | |||
- | == GridView Actions with Modal == | ||
- | To add a modal window (popup) from the '' | ||
- | |||
- | Add '' | ||
- | <code php> | ||
- | public function actionView($id) | ||
- | { | ||
- | if (Yii:: | ||
- | $modal = ''; | ||
- | $modal .= '< | ||
- | $modal .= ' | ||
- | <span aria-hidden=" | ||
- | $modal .= ' | ||
- | $modal .= '</ | ||
- | $modal .= '< | ||
- | $modal .= $this-> | ||
- | $modal .= '</ | ||
- | $modal .= '< | ||
- | $modal .= ' | ||
- | $modal .= '</ | ||
- | return $modal; | ||
- | } else { | ||
- | return $this-> | ||
- | ' | ||
- | ]); | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | In the view '' | ||
- | <code php> | ||
- | <?php | ||
- | |||
- | use yii\helpers\Html; | ||
- | use yii\grid\GridView; | ||
- | use yii\widgets\Pjax; | ||
- | |||
- | ?> | ||
- | <div class=" | ||
- | <!-- // ... --> | ||
- | <?php Pjax:: | ||
- | <?= GridView:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | [' | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | //... | ||
- | |||
- | // | ||
- | [ | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | | ||
- | $url, [' | ||
- | ); | ||
- | }, | ||
- | ' | ||
- | | ||
- | $url, [' | ||
- | ); | ||
- | }, | ||
- | ], | ||
- | ], | ||
- | ], | ||
- | ]); ?> | ||
- | |||
- | <?php | ||
- | $this-> | ||
- | " | ||
- | $(' | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | }); | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | }); | ||
- | }); | ||
- | "); | ||
- | |||
- | yii\bootstrap\Modal:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | //' | ||
- | // ' | ||
- | // ' | ||
- | //], | ||
- | ' | ||
- | ]); | ||
- | echo "< | ||
- | yii\bootstrap\Modal:: | ||
- | | ||
- | yii\bootstrap\Modal:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | //' | ||
- | // ' | ||
- | // ' | ||
- | //], | ||
- | echo "< | ||
- | ' | ||
- | ]); | ||
- | | ||
- | yii\bootstrap\Modal:: | ||
- | ?> | ||
- | |||
- | <?php Pjax:: | ||
- | </ | ||
- | |||
</ | </ | ||
Line 348: | Line 226: | ||
See also: [[http:// | See also: [[http:// | ||
+ | |||
+ | === Modal View (called from GridView action) using AJAX === | ||
+ | To add a modal window (popup) from the '' | ||
+ | |||
+ | Add '' | ||
+ | <code php> | ||
+ | public function actionView($id) | ||
+ | { | ||
+ | if (Yii:: | ||
+ | $modal = ''; | ||
+ | $modal .= '< | ||
+ | $modal .= ' | ||
+ | <span aria-hidden=" | ||
+ | $modal .= ' | ||
+ | $modal .= '</ | ||
+ | $modal .= '< | ||
+ | $modal .= $this-> | ||
+ | $modal .= '</ | ||
+ | $modal .= '< | ||
+ | $modal .= ' | ||
+ | $modal .= '</ | ||
+ | return $modal; | ||
+ | } else { | ||
+ | return $this-> | ||
+ | ' | ||
+ | ]); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the view '' | ||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | use yii\helpers\Html; | ||
+ | use yii\grid\GridView; | ||
+ | use yii\widgets\Pjax; | ||
+ | |||
+ | ?> | ||
+ | <div class=" | ||
+ | <!-- // ... --> | ||
+ | <?php Pjax:: | ||
+ | <?= GridView:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | [' | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | //... | ||
+ | |||
+ | // | ||
+ | [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | | ||
+ | $url, [' | ||
+ | ); | ||
+ | }, | ||
+ | ' | ||
+ | | ||
+ | $url, [' | ||
+ | ); | ||
+ | }, | ||
+ | ], | ||
+ | ], | ||
+ | ], | ||
+ | ]); ?> | ||
+ | |||
+ | <?php | ||
+ | $this-> | ||
+ | " | ||
+ | $(' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }); | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | }); | ||
+ | }); | ||
+ | "); | ||
+ | |||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | //' | ||
+ | // ' | ||
+ | // ' | ||
+ | //], | ||
+ | ' | ||
+ | ]); | ||
+ | echo "< | ||
+ | yii\bootstrap\Modal:: | ||
+ | | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | //' | ||
+ | // ' | ||
+ | // ' | ||
+ | //], | ||
+ | echo "< | ||
+ | ' | ||
+ | ]); | ||
+ | | ||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
+ | |||
+ | <?php Pjax:: | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
== Modal Confirmation (called from GridView action) == | == Modal Confirmation (called from GridView action) == | ||
Line 401: | Line 402: | ||
$.post({ | $.post({ | ||
url:'" | url:'" | ||
- | dataType: ' | ||
data: {keylist: keys}, | data: {keylist: keys}, | ||
success: function( data ) { | success: function( data ) { | ||
Line 409: | Line 409: | ||
console.log(data.data_post); | console.log(data.data_post); | ||
console.log(data.data_get); | console.log(data.data_get); | ||
- | } | + | }, |
+ | dataType: ' | ||
}); | }); | ||
} else { | } else { | ||
Line 478: | Line 479: | ||
' | ' | ||
]) ?> | ]) ?> | ||
+ | |||
+ | <?php | ||
+ | // Modal for Delete | ||
+ | yii\bootstrap\Modal:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | Html:: | ||
+ | ' | ||
+ | ]) . " " . | ||
+ | Html:: | ||
+ | ' | ||
+ | ]), | ||
+ | //' | ||
+ | ' | ||
+ | ]); | ||
+ | echo "< | ||
+ | echo " | ||
+ | echo "</ | ||
+ | yii\bootstrap\Modal:: | ||
+ | ?> | ||
<?php | <?php | ||
Line 507: | Line 529: | ||
$.post({ | $.post({ | ||
url:'" | url:'" | ||
- | dataType: ' | ||
data: {keylist: keys}, | data: {keylist: keys}, | ||
success: function( data ) { | success: function( data ) { | ||
Line 515: | Line 536: | ||
console.log(data.data_post); | console.log(data.data_post); | ||
console.log(data.data_get); | console.log(data.data_get); | ||
- | } | + | }, |
+ | dataType: ' | ||
}); | }); | ||
} else { | } else { | ||
Line 522: | Line 544: | ||
} | } | ||
", \yii\web\View:: | ", \yii\web\View:: | ||
- | ?> | ||
- | |||
- | <?php | ||
- | // Modal for Delete | ||
- | yii\bootstrap\Modal:: | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | Html:: | ||
- | ' | ||
- | ]) . " " . | ||
- | Html:: | ||
- | ' | ||
- | ]), | ||
- | //' | ||
- | ' | ||
- | ]); | ||
- | echo "< | ||
- | echo " | ||
- | echo "</ | ||
- | yii\bootstrap\Modal:: | ||
?> | ?> | ||
</ | </ |