title: Yii: error 404, your request is invalid upon deletion
body: <p>what i am doing is that when the admin login via webapp/user/login it has certain things to control. when ever i want to delete any data from there like, if i want to delete a picture of an event, it gives me an error "Error 400 Your request is invalid". what colud be the problem. i have posted the controller code of event table.</p>
  
  <pre><code>&lt;?php
  
  class EventController extends Controller
  {
      /**
      * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
      * using two-column layout. See 'protected/views/layouts/column2.php'.
      */
      public $layout='//layouts/column2';
  
      /**
      * @return array action filters
      */
      public function filters()
      {
          return array(
              'accessControl', // perform access control for CRUD operations
              'postOnly + delete', // we only allow deletion via POST request
          );
      }
  
      /**
      * Specifies the access control rules.
      * This method is used by the 'accessControl' filter.
      * @return array access control rules
      */
      public function accessRules()
      {
          return array(
              array('allow',  // allow all users to perform 'index' and 'view' actions
                  'actions'=&gt;array('index','view'),
                  'users'=&gt;array('*'),
              ),
              array('allow', // allow authenticated user to perform 'create' and 'update' actions
                  'actions'=&gt;array('create','update'),
                  'users'=&gt;array('@'),
              ),
              array('allow', // allow admin user to perform 'admin' and 'delete' actions
                  'actions'=&gt;array('admin','delete'),
                  'users'=&gt;array('admin'),
              ),
              array('deny',  // deny all users
                  'users'=&gt;array('*'),
              ),
          );
      }
  
      /**
      * Displays a particular model.
      * @param integer $id the ID of the model to be displayed
      */
      public function actionView($id)
      {
          $this-&gt;render('view',array(
              'model'=&gt;$this-&gt;loadModel($id),
          ));
      }
  
      /**
      * Creates a new model.
      * If creation is successful, the browser will be redirected to the 'view' page.
      */
      public function actionCreate()
      {
          $model=new Event;
  
          // Uncomment the following line if AJAX validation is needed
          // $this-&gt;performAjaxValidation($model);
  
          if(isset($_POST['Event']))
          {
                       $rnd = rand(0,9999);  // generate random number between 0-9999
              $model-&gt;attributes=$_POST['Event'];
                           $uploadedFile=CUploadedFile::getInstance($model,'image');
              $fileName = "{$rnd}-{$uploadedFile}";  // random number + file name
              $model-&gt;image = $fileName;
              if($model-&gt;save())
                               {
                  $uploadedFile-&gt;saveAs(Yii::app()-&gt;basePath.'/'.$fileName);  // image will uplode to rootDirectory/event/
                  $this-&gt;redirect(array('admin'));
              }
                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
          }
  
          $this-&gt;render('create',array(
          'model'=&gt;$model,
          ));
      }
  
      /**
      * Updates a particular model.
      * If update is successful, the browser will be redirected to the 'view' page.
      * @param integer $id the ID of the model to be updated
      */
      public function actionUpdate($id)
      {
          $model=$this-&gt;loadModel($id);
  
          // Uncomment the following line if AJAX validation is needed
          // $this-&gt;performAjaxValidation($model);
  
          if(isset($_POST['Event']))
          {
                      $_POST['Event']['image'] = $model-&gt;image;
              $model-&gt;attributes=$_POST['Event'];
                          $uploadedFile=CUploadedFile::getInstance($model,'image');
  
              if($model-&gt;save())
                              {
                  if(!empty($uploadedFile))  // check if uploaded file is set or not
                  {
                   $uploadedFile-&gt;saveAs(Yii::app()-&gt;basePath.'/../event/'.$model-&gt;image);
                  }
                  $this-&gt;redirect(array('admin'));
              }
                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
          }
  
          $this-&gt;render('update',array(
              'model'=&gt;$model,
          ));
      }
  
      /**
      * 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 actionDelete($id)
      {
          if(Yii::app()-&gt;request-&gt;isPostRequest)
          {
              // we only allow deletion via POST request
              $this-&gt;loadModel($id)-&gt;delete();
  
              // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
              if(!isset($_GET['ajax']))
                  $this-&gt;redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
          }
          else
              throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
      }
  
      /**
      * Lists all models.
      */
      public function actionIndex()
      {
          $dataProvider=new CActiveDataProvider('Event');
          $this-&gt;render('index',array(
              'dataProvider'=&gt;$dataProvider,
          ));
      }
  
      /**
      * Manages all models.
      */
      public function actionAdmin()
      {
          $model=new Event('search');
          $model-&gt;unsetAttributes();  // clear any default values
          if(isset($_GET['Event']))
              $model-&gt;attributes=$_GET['Event'];
  
          $this-&gt;render('admin',array(
              'model'=&gt;$model,
          ));
      }
  
      /**
      * Returns the data model based on the primary key given in the GET variable.
      * If the data model is not found, an HTTP exception will be raised.
      * @param integer $id the ID of the model to be loaded
      * @return Event the loaded model
      * @throws CHttpException
      */
      public function loadModel($id)
      {
          $model=Event::model()-&gt;findByPk($id);
          if($model===null)
              throw new CHttpException(404,'The requested page does not exist.');
          return $model;
      }
  
      /**
      * Performs the AJAX validation.
      * @param Event $model the model to be validated
      */
      protected function performAjaxValidation($model)
      {
          if(isset($_POST['ajax']) &amp;&amp; $_POST['ajax']==='event-form')
          {
              echo CActiveForm::validate($model);
              Yii::app()-&gt;end();
          }
      }
  }
  </code></pre>