2014-04-27 57 views
0

我想將一個php變量傳遞給模態窗口,我正在做的是使用此鏈接打開模態窗口,但是我想將變量傳遞給此鏈接並在模態窗口獲得相同的變量,我嘗試這樣做是爲了追加一些DIV文本,但它返回的HTML,我無法查詢如何通過鏈接將PHP變量傳遞給yiibooster模態窗口

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

得到,當我點擊這個按鈕,我得到了模態窗口如何得到變量設置在按鈕 這裏是簡單的模態代碼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(); ?> 

在此先感謝

回答

0

您應該創建一個Widget。

注意:我從其他帖子複製下面。它的作用像魅力。

首先創建一個新的小部件。假設名稱是CategoryWidget。將這個小部件放在組件目錄protected/components下。

class CategoryWidget extends CWidget { 

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

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

然後爲這個小部件創建一個視圖。文件名是category.php。把它放在保護/組件/視圖 category.php

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

然後調用您的主要佈局這個小程序。 main.php //你的代碼...

<?php $this->widget('CategoryWidget') ?> 
相關問題