我正在使用Yii,如果我点击更新图标,在CGridView中,id=
之后没有任何内容(以quwey字符串形式)
URL?r=employes/update&id=
查看
<?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 :(得分:1)
您没有将id值传递给网格中的更新按钮。如下所示更改您的网格视图:
......
......
'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))',
)
)
......
......