Answer the question
In order to leave comments, you need to log in
How to call modal window from controllera in view?
Good afternoon everyone! It is necessary to call the modal window from the controller in the view.
In the controller the following function
public function actionFulfilled($id)
{
$model = $this->findModel($id);
$model->status = Zakaz::STATUS_EXECUTE;
$model->id_unread = 0;
if($model->fact_oplata === null || $model->fact_oplata === 0){
Yii::$app->session->addFlash('errors', 'Нельзя закрыть заказ с оплатой 0!');
$modalErrorOplata = true;
return $this->redirect(['admin']);
} else {
if ($model->save()) {
Yii::$app->session->addFlash('update', 'Выполнен заказ №'.$model->prefics);
return $this->redirect(['admin']);
}else {
print_r($model->getErrors());
Yii::$app->session->addFlash('errors', 'Произошла ошибка!');
}
}
}
<?php
var_dump($modalErrorOplata);
if($modalErrorOplata === true){
$script = <<<JS
function modalView(button, modal) {
$('body').on('click', button, function(e){
e.preventDefault();
$(modal).modal('show')
.find('.modalContent')
.load($(this).attr('value'));
});
}
modalView('.modalZakazview-button', '#modalZakazview');
JS;
$this->registerJs($script);
}
?>
<?php Modal::begin([
'id' => 'modalZakazview',
'header' => '<h2>Полный просмотр</h2>'
]);
echo '<div class="modalContent"></div>';
Modal::end(); ?>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
You can pass the parameter like this
But! Modal window you open after clicking. When redirecting, you need to somehow simulate a click on the button. I think it would be better to look towards ajax sending data and receiving a response.
The controller generates html based on the view and sends it to the browser in response to a request from the browser. The modal exists when js starts to work, that is, in the browser. So your question is completely wrong.
Given that you have, .load($(this).attr('value'));
as I understand it, ajax is going somewhere, so apparently, according to the result of this ajax, you either need to open or not a modal. If you formulate the problem completely, and not your vision of its solution, we may find a more correct algorithm.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question