1

我正在使用 Symfony2,并且我有一个带有 Rss 实体的 ReaderBundle。

我为这个实体创建了 CRUD。

php app/console generate:doctrine:crud --entity=RSSReaderBundle:Rss --format=annotation --with-write

在我连接缓存之前,一切都很好。

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppCache.php';
require_once __DIR__.'/../app/AppKernel.php';

Debug::enable();

$kernel = new AppKernel('dev' , true);
$kernel->loadClassCache();
$kernel = new AppCache($kernel); // THAT STRING IS MAIN PROBLEM
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

然后当我试图删除一些记录时,我出现了这个错误: 我创建了一个明确指示方法的表单:

No route found for "POST /rss/delete/30": Method Not Allowed (Allow: DELETE)
405 Method Not Allowed



private function createDeleteForm($id)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('rss_delete', array('id' => $id)))
            ->setMethod("DELETE")
            ->add('submit', 'submit', array('label' => 'Delete'))
            ->getForm()
        ;
    }

我还没有发现问题。请帮忙

4

4 回答 4

1

这个问题从 symfony2.2 开始出现,见https://github.com/symfony/symfony-standard/commit/1970b831f8843a5cf551e9d88404cb62f21b90f9

您需要Symfony\Component\HttpFoundation\Request::$httpMethodParameterOverride在 app.php 文件中手动修改布尔值:

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();
于 2015-08-26T18:22:17.857 回答
0

我们必须删除带有注释“THAT STRING IS MAIN PROBLEM”的字符串。缓存工作都一样。并且 CRUD 正常工作

于 2013-10-26T11:32:20.450 回答
0

我遇到了与您相同的问题(使用 PUT 和 DELETE HTTP 方法),但我不明白您的解决方案。

您是否:
a) 只是摆脱 // 那个字符串是主要问题

b) 摆脱 $kernel = new AppCache($kernel); // 那个字符串是主要问题

解决方案 b) 与不使用缓存相同,因此在我的情况下,它没有帮助,因为页面需要很长时间才能加载。

@Nifr:我认为有 PUT 和 DELETE 方法。我按照此链接上的说明在我的表单中使用它们:http: //symfony.com/fr/doc/current/cookbook/routing/method_parameters.html 所以事实上,Symfony2 能够判断一个方法是 PUT,DELETE ,发布或获取。但不知何故,缓存不能...

有什么帮助吗?

编辑:我找到了一个不涉及更改 app.php 文件中的任何内容的解决方案。基本上,问题来自于 symfony2 的请求对象的 getMethod 方法不知道 PUT 或 DELETE 方法。关键是在 AppCache.php 文件中更改它。

我们只需要重写 AppCache.php 文件的方法 invalidate :

protected function invalidate(Request $request, $catch = false)
{
  $request->setMethod($request->request->get('_method'));
  return parent::invalidate($request, $catch);
}

在这里,我只是通过表单发布的方法更改请求的方法。

于 2014-09-25T08:07:11.183 回答
0

html 表单中没有method="DELETE"……至少几乎所有浏览器都不支持 - 仅在 ajax 请求中。

通过允许对路由的 DELETE 和 POST 请求来解决此问题。

于 2013-10-04T16:24:06.387 回答