2015-08-23 27 views
0

每個模型ID都有一個相應的靜態頁面,例如我的表格的ID = 1在我的視圖中有一個靜態頁面,名稱爲1.php。所以當我點擊鏈接按鈕(在ClistView中實現)時,它應該顯示相應的靜態頁面。
我該如何實現此功能?
Yii - 鏈接到給定模型ID的靜態頁面

<?php 
     echo CHtml::link('View Detail', array('$data->id.php'), 

      // i want 1.php to be displayed for $data->id =1 and 2.php for $data->id= 2 

      array('id'=>'mylink','class'=>'btnPrint btn btn-danger', 
       'target'=>'_blank', 
      )); 
     ?> 

回答

1
<?php 
echo CHtml::link(
    'View Detail', 
    $this->createUrl('site/static', array('id' => $data->id)), 
    array(
     'id' => 'mylink', 
     'class' => 'btnPrint btn btn-danger', 
     'target' => '_blank', 
    ) 
); 

而在你的控制器,你可以創建如下動作:

public function actionStatic($id) 
{ 
    $this->render($id); 
}