Hello Out there.
I was wondering if there is a possibility of have modals with dynamic content.
So lets say in a normal index view, I would like to have a hyperlink (per shown record) which opens a Bootstrap Modal. But the content of it should come form an action via Ajax, so loaded on click.
I do get it to work like below. This is to retrieve just one parameter from the model.
Now I am thinking of using the default DetailView to show more info of that model.
But if I echo $model it returns an error.
Is there a way to get this?
My view File is this:
<div id="myModal" class="modal hide">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Title</h3>
</div>
<div class="modal-body">
<div id="modalContent" style="display:none;">
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-info" data-dismiss="modal" >Close</a>
</div>
</div>
<a href="#myModal" data-toggle="modal" id="<?php echo $data->id ?>" title="Show Image Info">Info</a>
<script>
$("a[data-toggle=modal]").click(function()
{
$.ajax({
cache: false,
type: 'POST',
// url: 'image/viewImage/211785',
url: "<?php echo $this->createUrl('image/viewImage') ?>"+$(this).attr('id'),
data: '',
success: function(data)
{
$('#myModal').show();
$('#modalContent').show().html(data);
}
});
});
</script>
My controller is this:
public function actionViewImage($id)
{
$model = $this->loadModel($id);
echo $model->name; // This works and is displaying the name inside the modal
//echo $model; // this one does throw an error
}
the error is : Object of class Image could not be converted to string
Any hints?
I did try to use renderPartial before and opening the content inside a CJUDialog, but this had some drawbacks for my case.
So the question is, can I make a model available in this way?
gb5256