0

I want to pass a php variable to modal window , what i am doing is opening a modal window using this link , but i want to pass a variable to this link and get same variable in modal window , i try to to do this to append a text in some div but it return html that i am unable to get in query

 echo CHtml::link(
                                'Set Recipe', '', array(
                            'class' => 'testclass',
                            'id' => $finalDate,
                            'data-toggle' => 'modal',
                            'data-target' => '#myModal',
                            'fahadVar' => $finalDate
                        ));

and when i click this button i got modal window how to get variable set in button Here is simple modal code of yiibooster

     <div class="modal-body">
<p>One fine body...</p>
</div>

<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'label' => 'Save changes',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Close',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>

<?php $this->endWidget(); ?>

thanks in advance

FahadAkram
  • 445
  • 1
  • 5
  • 25

1 Answers1

0

You should create a Widget.

Note: I copied below from another post. It works like charm.

First Create a new widget. Let say the name is CategoryWidget. Put this widget under components directory protected/components.

class CategoryWidget extends CWidget {

    public function run() {
        $models = Category::model()->findAll();

        $this->render('category', array(
            'models'=>$models   
        ));
    }
}

Then create a view for this widget. The file name is category.php. Put it under protected/components/views category.php

<?php if($models != null): ?>
<ul>
    <?php foreach($models as $model): ?>
    <li><?php echo $model->name; ?></li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

Then call this widget from your main layout. main.php // your code ...

<?php $this->widget('CategoryWidget') ?>
Sam
  • 265
  • 4
  • 15