Method Not Allowed (#405)

[color=#A94442]

[/color][color=#A94442]in mygridview my default delete button is not working. its showing an error like " Method Not Allowed. This url can only handle the following request methods: POST." when i use the default layout, delete button works perfect, but i wanna use a differenet layout .[/color]

Without Code I can only guess:

Maybe it has something todo with the VerbFilter in your Controller.

Link:

http://www.yiiframework.com/doc-2.0/guide-structure-filters.html

Look for “VerbFilter” and read. :)

Regards

Delete should always use POST since it changes the contents of the database. The HTTP spec says that GET should only be used for idempotent calls that do not change state, which means calls that always do the same thing and don’t change the system. For this reason, they are safe to cache and can be called multiple times on failure without danger of doing something twice. A POST on the other hand is usually expected to change the system, which is why your browser sometimes asks if it is OK to “resubmit” the previous form.

AsMetaCrawler said, you can change the allowed methods, either in the configuration (urlManager->rules section) or you can add it as a behavior in the controller itself:


public function behaviors()

    {

        return [

            'verbs' => [

                'class' => VerbFilter::className(),

                'actions' => [

                    'delete' => ['post'],

                ],

            ],

        ];

    }

thanks guys