Reputation: 201
i'm trying to render view from another controller in active form when creating new data. my purpose is only for reference when render the view. how to achieve this in yii2?
ilustration like this : active form in controller-B/create
and there is a button to view the modal (controller-A/list)
and select data what user want and then render a view beside active form (controller-A/view?id=xx)
.
Upvotes: 0
Views: 613
Reputation: 9368
Controller
$view = $this->render('view', [
'model' => $this->findModel($id),
]);
return json_encode($view);
HTML
<div class="row">
<div class="col-sm-4">
// ActiveForm code here
</div>
<div class="col-sm-8" id="whatever" style="display:none"> // initially hidden
// render another view here
</div>
Jquery
$(document).on('click', '.select-row', function(){
var id = $(this).attr('data-id');
$.get('../pengiriman-produksi/get-data', {id : id}, function(data){
var data = $.parseJSON(data);
$('#whatever').show();
$('#whatever').html(data);
});
$('#modalPengiriman').modal('hide');
});
Upvotes: 1