浏览代码

Merge pull request #1184 from mweimerskirch/patch-1

Fix for "delete" action not working with Sf2.2
Thomas 12 年之前
父节点
当前提交
bf3a584c07
共有 1 个文件被更改,包括 16 次插入1 次删除
  1. 16 1
      Controller/CRUDController.php

+ 16 - 1
Controller/CRUDController.php

@@ -61,6 +61,21 @@ class CRUDController extends Controller
         return $this->get('request')->isXmlHttpRequest() || $this->get('request')->get('_xml_http_request');
     }
 
+    /**
+     * Returns the correct RESTful verb, given either by the request itself or
+     * via the "_method" parameter.
+     * 
+     * @return string HTTP method, either 
+     */
+    protected function getRestMethod()
+    {
+        $request = $this->getRequest();
+        if(Request::getHttpMethodParameterOverride() || !$request->request->has('_method')) {
+            return $request->getMethod(); 
+        }
+        return $request->request->get('_method');
+    }
+
     /**
      * Sets the Container associated with this Controller.
      *
@@ -211,7 +226,7 @@ class CRUDController extends Controller
             throw new AccessDeniedException();
         }
 
-        if ($this->getRequest()->getMethod() == 'DELETE') {
+        if ($this->getRestMethod() == 'DELETE') {
             try {
                 $this->admin->delete($object);