Dynamic Modal Bootstrap

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">&times;</button>



    <div class="modal-body">            

        <div id="modalContent" style="display:none;">



    <div class="modal-footer">

      <a href="#" class="btn btn-info" data-dismiss="modal" >Close</a>



<a href="#myModal" data-toggle="modal" id="<?php echo $data->id ?>" title="Show Image Info">Info</a>





               cache: false,

               type: 'POST',

//               url: 'image/viewImage/211785',

               url: "<?php echo $this->createUrl('image/viewImage') ?>"+$(this).attr('id'),

               data: '',

               success: function(data) 









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?


You need to render partially a view inside the model body, that’s by returning the whole view with renderPartial, something like:

public function actionViewImage($id)


            $model = $this->loadModel($id);


            echo $this->renderPartial('_yourpartialview', array('model' => $model));


Atleast is how I do this in all my modals.

The reason for this error is, you are trying to echo an object or array. Use print_r() or var_dump() functions to print the $model