App Record Delete

i created a app by the gii. when i press delete on the record, it shows the following error.

04:01:51.782932 error exception.CHttpException.400

exception ‘CHttpException’ with message ‘Your request is invalid.’ in

/home/yii/domains/localhost/public_html/framework/web/CController.php:1119

Stack trace:

#0

/home/yii/domains/localhost/public_html/framework/web/filters/CInlineFilter.php(59):

CController->filterPostOnly(Object(CFilterChain))

#1

/home/yii/domains/localhost/public_html/framework/web/filters/CFilterChain.php(131):

CInlineFilter->filter(Object(CFilterChain))

#2

/home/yii/domains/localhost/public_html/framework/web/filters/CFilter.php(41):

CFilterChain->run()

#3

/home/yii/domains/localhost/public_html/framework/web/CController.php(1146):

CFilter->filter(Object(CFilterChain))

#4

/home/yii/domains/localhost/public_html/framework/web/filters/CInlineFilter.php(59):

CController->filterAccessControl(Object(CFilterChain))

#5

/home/yii/domains/localhost/public_html/framework/web/filters/CFilterChain.php(131):

CInlineFilter->filter(Object(CFilterChain))

#6

/home/yii/domains/localhost/public_html/framework/web/CController.php(292):

CFilterChain->run()

#7

/home/yii/domains/localhost/public_html/framework/web/CController.php(266):

CController->runActionWithFilters(Object(CInlineAction), Array)

#8

/home/yii/domains/localhost/public_html/framework/web/CWebApplication.php(283):

CController->run(‘delete’)

#9

/home/yii/domains/localhost/public_html/framework/web/CWebApplication.php(142):

CWebApplication->runController(‘equipmentswitch…’)

#10

/home/yii/domains/localhost/public_html/framework/base/CApplication.php(162):

CWebApplication->processRequest()

#11 /home/yii/domains/localhost/public_html/server/index.php(13):

CApplication->run()

#12 {main}

REQUEST_URI=/server/index.php/equipmentswitch/delete/1

HTTP_REFERER=htt/localhost/server/index.php/equipmentswitch/admin


The code generated by Gii by default allows deletes using only POST requests. You can check whether the request is a POST. For reference, check the filters that are setup on your action.

Here is the ActionDelete in controller

public function actionDelete($id)

    {


            $this->loadModel($id)->delete();





            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser


            if(!isset($_GET['ajax']))


                    $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));


    }

If you have a $id parameter, it requires $id to be passed as a GET parameter.

Assuming that ‘id’ is the name of the parameter that you require, and that it’s coming through POST, you need something like:




public function actionDelete()

{

    $id = Yii::app()->request->getPost('id');


    $this->loadModel($id)->delete();


    // Other stuff

} 



You will probably want to check the validity of $id before deleting.

This is happening due to a "postOnly" filter set for your delete action. Please check your [font="Courier New"]filters[/font] method.