在yii中删除CGridView中的操作。

时间:2014-04-29 05:45:34

标签: php yii yii-widgets

我正在使用CGRidVeiw列出我的数据库记录, 在每个记录中,我有一个编辑和删除按钮。除了删除操作之外,它正在运行fn9,实际上它在单击删除图标后显示错误,但它仍然正常工作.Below实际上是什么样的按钮,< / p>

enter image description here

点击刷新后没有显示记录。 我有我的观点和控制器如下。

//位指示

  public function actionDeleteEmployer() {

        $model = new AdminDeleteEmployer();

        if (isset($_GET['id'])) {
            $id = $_GET['id'];
        }

        $query = "DELETE FROM user,jobs USING user INNER JOIN jobs ON jobs.user_id = user.id WHERE user.id =$id";

        Yii::app()->db->createCommand($query)->queryAll();

         $this->redirect('admin/site/ManageEmployers');
    }

///视图

管理雇主

<div class="form">
    <?php
    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $model->search(),
        'ajaxUpdate'=>false,
        //   'filter' => $model,
        'columns' => array(
            array(
                'name' => ' Employer ID',
                'type' => 'raw',
                'value' => 'CHtml::encode($data->id)',
                'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
            // 'filter'=>'false' /* for hiding filter boxes */
            ),
            array(
                'name' => 'Created On',
                'type' => 'raw',
                'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->created)))',
                'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
            // 'filter'=>'false' /* for hiding filter boxes */
            ),
            array(
                'name' => 'Account Name',
                'type' => 'raw',
                'value' => 'CHtml::encode($data->name)',
                'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
            // 'filter'=>'false' /* for hiding filter boxes */
            ),
            array(
                'name' => 'Email',
                'type' => 'raw',
                'value' => 'CHtml::encode($data->email)',
                'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
            // 'filter'=>'false' /* for hiding filter boxes */
            ),
            array(
                'name' => 'Last Active On',
                'type' => 'raw',
                'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->modified)))',
                'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
            // 'filter'=>'false' /* for hiding filter boxes */
            ),
            array(
                'class' => 'CButtonColumn',
                'deleteConfirmation' => 'Are you sure you want to delte this item?',
                'template' => '{view}{delete}',
                'buttons' => array(
                    'view' => array('label' => 'view',
                        'url' => 'Yii::app()->controller->createUrl("ViewEmployerActivity",array("id"=>$data["id"]))'),
                    'delete' => array('label' => 'delete',
                        'url' => 'Yii::app()->controller->createUrl("DeleteEmployer",array("id"=>$data["id"]))'),
                )
            )
        ),
    ));
    ?>

</tbody>
</table>

1 个答案:

答案 0 :(得分:1)

重定向到管理员操作

Yii::app()->db->createCommand($query)->execute();
$this->redirect(array('admin'))