2014-04-19 41 views
0

我在yii中更新頁面時出現錯誤400。我沒有改變毛病的錯誤400:Yii

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格式的任何accessRules():

'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的功能。我想問題是「複合鍵」。

+0

在main.php中啓用了模塊嗎? – Anri

+0

是的,它被啓用 – user3496974

回答

0

當你獲得400時,你的URL是什麼?您可能不會發送ID,因此無法找到必須重定向的頁面。

您是否使用標準的CRUD更新操作?或者你改變了什麼?您可以嘗試在保存時轉儲$ model-> 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, 
    )); 
} 
+0

是的,它是同樣的事情,當我在我的模型中添加一個複合鍵時,我的CRUD停止工作 - public function primaryKey(){return array('name','email');} – user3496974

+0

PK在你的數據庫? 也許這將有助於:http://www.yiiframework.com/forum/index.php?/topic/6863-composite-primary-key-not-supported-by-crud-command/ – Timvp

+0

是的,我有一個PK在我的分貝。後來我嘗試使用該功能添加複合鍵,但它不起作用 – user3496974