0

我正在使用 CGRidVeiw 从数据库中列出我的记录,在每条记录中我都有一个编辑和删除按钮。除了删除操作之外,一切都在工作 fn9,实际上它在单击删除图标后显示错误,但它仍然有效。下面是它实际外观的快照,

在此处输入图像描述

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

//控制器

  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>
4

1 回答 1

1

重定向到管理员操作

Yii::app()->db->createCommand($query)->execute();
$this->redirect(array('admin'))
于 2014-04-29T08:15:39.570 回答