3
  • When i delete a Record in GridView i got this Error on my Hosting Server.
  • Local its working without Problems.

What i dont understand is:

The error says -> Method Not Allowed. This url can only handle the following request methods: POST.

When i look at my Code:

public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

ITS POST?!

When i change to GET it works without error, but also without Delete Confirmation Prompt....

I have to Questions:

  • Why i get a Message -> allows only post, when it is Post?
  • How do i get an Delete Confirmation, when i change to GET

Sorry for my English and Thank you so much for help.

enter image description here

  • Are you sure the local and the remote host are the same? No special web server configuration at the remote host? Can you show us the code that calls the delete URL? – robsch May 03 '17 at 13:59
  • check fpr both config (loacalhost and server) files .. could you have not the same values .. and let me know – scaisEdge May 03 '17 at 16:26
  • Are there any JavaScript errors? – mmonem May 03 '17 at 18:01
  • post your view page here. – Irfan Ali May 04 '17 at 06:27
  • I am getting the same error and it's working fine on my localhost and in fact on the my test server but when I uploaded to my client server I am facing the same issue. – nitin Nov 20 '17 at 11:23

1 Answers1

0

You probably have a VerbFilter set up in your controller behaviors method which is preventing to call the delete action to be called with GET method.

Something similar:

public function behaviors()
{
    return [
        'verbs' => [
            'class' => \yii\filters\VerbFilter::className(),
            'actions' => [
                'index'  => ['GET'],
                'view'   => ['GET'],
                'create' => ['GET', 'POST'],
                'update' => ['GET', 'PUT', 'POST'],
                'delete' => ['POST', 'DELETE'],
            ],
        ],
    ];
}

You can read more about VerFilter here

You have to options:

  1. Delete the VerbFilter from the behaviors method
  2. You can add the data-method="post" property to your link which and this will fire a POST request instead of a GET.
Szántó Zoltán
  • 883
  • 11
  • 25