YII 調用delete action 會出現Bad Request Your request is invalid.

來源:互聯網
上載者:User
// view 下的
$v): ?>

user_id; ?>
user_name; ?>
user_realname;?>
user_password;?>
user_sex; ?>
user_roles; ?>
user_birthday; ?>
user_relation; ?>
dep_id; ?>
user_address; ?>
user_allowed; ?>
user_createtime); ?>
user_lasttime; ?>
createUrl('/parkuser/view',array('id'=>$v->user_id)) ?>">查看
createUrl('/parkuser/update',array('id'=>$v->user_id))?>">修改
createUrl('/parkuser/delete',array('id'=>$v->user_id))?>">刪除





//問題在三個操作上邊 查看 修改都可以用 唯獨刪除不行

//delete action


class DeleteAction extends Publics{


/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function run(){

$this->delete();
}
public function delete(){
$id = intval($_GET['id']);

$model=ParkUser::model()->findByPk($id);
if($model===null) die("");
$model->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->getController()->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
}

?>


回複討論(解決方案)

$model->delete();

的時候沒有把id傳入進去。

以前在維護網站的時候發現如果某個js傳漏了,或者錯誤都可能導致這種刪除刪不掉的情況,遇到過一次,重新傳資源

id 傳過去了 地址欄變化為:http://localhost/park/index.php?r=parkuser/delete&id=11

補充一下 controller 求牛人解決下

public function actions(){
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),

'page'=>array(
'class'=>'CViewAction',
),
'create'=>'application.controllers.parkuser.CreateAction',
'update'=>'application.controllers.parkuser.UpdateAction',
'view'=>'application.controllers.parkuser.ViewAction',
'index'=>'application.controllers.parkuser.IndexAction',
'admin'=>'application.controllers.parkuser.AdminAction',
'delete'=>'application.controllers.parkuser.DeleteAction',
);

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.