错误400为crud:Yii

时间:2014-04-19 09:58:27

标签: php yii

我在yii中更新页面时遇到错误400。我没有更改任何accessRules()

public function accessRules()
{
return array(
array('allow',  // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('@'),
    ),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('@'),
),
array('deny',  // deny all users
'users'=>array('*'),
),
);
}


public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}

我还在urlmanager中启用了URL格式:

'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
     '<action>'=>'site/<action>'
        ),
    ),

我仍然只为我的一个模块得到错误400,并且无法弄明白。

我已将复合主键添加到我的数据库中,并且错过了检查CRUD的功能。我猜问题是“复合键”。

1 个答案:

答案 0 :(得分:0)

获得400后,您的网址是多少?您可能不会发送ID,因此无法找到必须重定向的页面。

您是否使用标准CRUD更新操作?或者你改变了什么?您可以尝试在保存时转储$ model-&gt; id以查看它是否已发送?像这样:

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

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

    if (isset($_POST['Model'])) {
        $model->attributes = $_POST['Model'];
        if ($model->save())
            // comment the line underneath
            // $this->redirect(array('view', 'id' => $model->id)); 
            var_dump($model->id);
            die();
    }

    $this->render('update', array(
        'model' => $model,
    ));
}
相关问题