2013-10-05 42 views
1

我使用Yii,在CGridView如果我以後id=查詢字符串值中缺少更新圖標:CGridView(Yii的)

URL?r=employes/update&id= 

查看

單擊更新圖標,沒有什麼是正在添加(在quwey字符串)
<?php 
$this->widget('zii.widgets.grid.CGridView', array( 
'id'=>'employee-grid', 
'dataProvider'=>$model->EmpList(), 
'columns'=>array(
    'employee_no', 
    .... 
    'date_created', 
    array(  
    'class'=>'CButtonColumn', 
    'template'=>'{update} {delete}', 
),    
), )); 
?> 

什麼問題?


控制器

public function actionIndex() 
     { 
       // here is your code for this action 
       $model = new Emp; 
       //    print_r ($_POST); 
       if(isset($_POST['Emp'])) { 
       .. 
       .. 
       $connection = Yii::app()->db2 ; //Connect with 2nd db. 
       .. 
       .. 
       $command1 = 'Insert Query' // Insert Query here 
       $cmd1 = $connection->createCommand($command1); 
       $cmd1->execute(); 

        } 

       $this->render('index', array(
             'model'=>$model, 
             'id'=>$model->extension, 
             )); 

     } 


     public function actionUpdate($id) 
     { 
       $model=$this->loadModel($id); 

       // Uncomment the following line if AJAX validation is needed 
       // $this->performAjaxValidation($model); 

       if(isset($_POST['Emp'])) 
       { 
         $model->attributes=$_POST['Emp']; 
         if($model->save()) 
           $this->redirect(array('view','id'=>$model->emp_id)); 
       } 

       $this->render('update',array(
         'model'=>$model, 
       )); 
     } 

模型

class Emp extends DB2 
{ 

public function getDbConnection() 
     { 
       //return self::getCCDbConnection(); 
       return Yii::app()->dbcc; 
     } 
.. 
.. 
.. 

public function ExtensionList() 
{  
    $criteria=new CDbCriteria; 
    $criteria->select='emp_id,emp_type,..date_created'; 
    $criteria->condition = "emp_type = 'USER'"; 

    return new CActiveDataProvider($this, array(
    'criteria'=>$criteria, 
    'pagination' => array('pageSize' => 5), 
));   
} 
.. 
.. 
.. 

} 
+0

我有更新我的問題 – ungalnanban

回答

1

您還沒有id值傳遞給更新按鈕在網格中。改變你的gridview如下:

...... 
...... 
'template'=>'{update} {delete}', 
'buttons'=>array 
     (
     'update'=>array 
      (
       'url'=>'Yii::app()->createUrl("employes/update",$params=array("id"=>$data->emp_id))', 
      ), 
      'delete'=>array 
      (
      'url'=>'Yii::app()->createUrl("employes/delete",$params=array("id"=>$data->emp_id))', 
     ) 
     ) 
...... 
...... 
+0

我收到錯誤作爲'未定義變量:模型'。我已經使用'gii'生成代碼,它們工作正常,但不傳遞id值。怎麼樣? – ungalnanban

+1

嘗試$數據而不是模型。 – redGREENblue

+0

謝謝,我用$數據工作。我們需要在這裏解析ID嗎? – ungalnanban