2012-10-01 23 views
0

如何將提取的數據(在這種情況下爲$arr)返回到我的視圖 (我可以像處理表格一樣操作)。 如果我有這樣的通過AJAX處理我的控制器操作:如何將獲取的數據返回到我的視圖?

public function actionFetchregularload(){ 
      $criteria = new CDbCriteria; 
      $criteria->limit = 15; 
      $criteria->condition='semester = 2'; 
      $criteria->select = array('subjCode','subjDesc','lec','lab','units'); 
      $criteria->addSearchCondition('yrLvl', $_GET['yrlevel']); 
      $data = CompeProspectusA::model()->findAll($criteria); 
      $arr = array(); 
      foreach ($data as $item){ 
        $arr[] = array(
          'subjcode' => $item->subjCode, 
          'subjdesc' => $item->subjDesc, 
          'lab' => $item->lab, 
          'lec' => $item->lec, 
          'units' => $item->units, 
        ); 
      } 
    } 

回答

1

讓你的桌子或別的什麼景緻,在你的actionFetchregularload()使用renderPartial()這樣的:

$this->renderPartial('_table', array('arr'=>$arr), false, true);

在你的主查看你可以使用CHtml::ajaxLink選項(其中「#contentdiv」是你的表格div的編號):

CHtml::ajaxLink(
     "Update table", 
     Yii::app()->createUrl('controller/fetchregularload'), 
     array( //ajaxOptions 
      'type' => 'POST', 
      'beforeSend' => "function(request) { 
       $('#contentdiv').addClass('loading'); //add .loading class while loading - you can add background image 
      }", 
      'success' => "function(data) { 
       $('#contentdiv').removeClass('loading'); 
       document.getElementById('contentdiv').innerHTML=data; 
      }", 
     ), 
     //htmlOptions 
     array('href' => Yii::app()->createUrl('controller/fetchregularload')); 
    ); 
+0

請看看我的代碼: – eggshot

+0

http://pastebin.com/3gzEAULs – eggshot

+0

需要您查看代碼才能完成圖片 –

相關問題