Hi guys,
I’m just wondering if any of you have a better way of doing this?
I am using Yiibooster and have a TbButton which when clicked, should display a modal dialog.
The method shown at the Yiibooster site is nice and simple, but I would like to separate the modal code into separate files so that I don’t clutter my view up too much.
My current solution is to use sessions as such:
main view
// on clicking the button, the session is set
$this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Upload',
'type' => 'primary',
'htmlOptions' => array(
'data-toggle' => 'modal',
'data-target' => '#myModal',
'onClick' => Yii::app()->session['uploads'] = true,
),
)
);
?>
<div>
<?php
// if the session is set, render the view file containing the modal code
if (isset(Yii::app()->session['uploads'])) {
unset(Yii::app()->session['uploads']);
$this->renderPartial('_upload', array('model'=>$model, 'var'=>$myVar), false, false);
}
?>
</div>
So when the Upload button is clicked, I get a modal dialog and everything works. However I would like to take that logic out of the view, drop the sessions and use an action in the controller instead. I figure that it is something to do with ajaxOptions but I just can’t figure it out.
As I said, it is working but I will be making use of a lot of modal dialogs and my method just seems dirty!
Thanks