Caching symfony2积垢和;http缓存
我使用的是Symfony2,我有一个ReaderBundle,它有一个Rss实体 我为这个实体创建了CRUDCaching symfony2积垢和;http缓存,caching,symfony,crud,http-caching,Caching,Symfony,Crud,Http Caching,我使用的是Symfony2,我有一个ReaderBundle,它有一个Rss实体 我为这个实体创建了CRUD php app/console generate:doctrine:crud --entity=RSSReaderBundle:Rss --format=annotation --with-write 在我连接缓存之前,一切都很好。 $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __
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);
然后,当我试图删除一些记录时,我会出现以下错误:
未找到“POST/rss/delete/30”的路由:不允许使用方法(允许:删除)
405方法不允许
我创建了一个表单,清楚地指明了方法:
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('rss_delete', array('id' => $id)))
->setMethod("DELETE")
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
我没有发现问题。请帮助html表单中没有method=“DELETE”
。。。至少在几乎所有浏览器中都不受支持-仅在ajax请求中受支持
通过允许删除和向路由发送请求来解决此问题。html表单中没有method=“DELETE”
。。。至少在几乎所有浏览器中都不受支持-仅在ajax请求中受支持
通过允许删除和向路由发送请求来解决此问题。我们必须删除带有注释“该字符串是主要问题”的字符串。缓存仍在工作。而且CRUD工作正常我们必须删除带有注释“该字符串是主要问题”的字符串。缓存仍在工作。CRUD工作正常我遇到了与您相同的问题(使用PUT和DELETE HTTP方法),但我不理解您的解决方案 你:
a) 只要去掉//这个字符串就是主要问题
或
b) 摆脱$kernel=新的AppCache($kernel);//那个字符串是主要问题 解决方案b)与不使用缓存相同,因此在我的情况下,它没有帮助,因为加载页面需要很长时间 @Nifr: 我以为有方法放和删除。我按照此链接上的说明在表格中使用它们: 所以事实上,Symfony2能够判断一个方法是PUT、DELETE、POST还是GET。但无论如何,缓存不能 有什么帮助吗 编辑: 我找到了一个解决方案,它不需要更改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);
}
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();
在这里,我只是通过表单中发布的方法更改请求的方法。我有与您相同的问题(使用PUT和DELETE HTTP方法),但我不理解您的解决方案 你:
a) 只要去掉//这个字符串就是主要问题
或
b) 摆脱$kernel=新的AppCache($kernel);//那个字符串是主要问题 解决方案b)与不使用缓存相同,因此在我的情况下,它没有帮助,因为加载页面需要很长时间 @Nifr: 我以为有方法放和删除。我按照此链接上的说明在表格中使用它们: 所以事实上,Symfony2能够判断一个方法是PUT、DELETE、POST还是GET。但无论如何,缓存不能 有什么帮助吗 编辑: 我找到了一个解决方案,它不需要更改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);
}
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();
在这里,我只是通过表单中发布的方法更改请求的方法。此问题自symfony2.2以来出现,请参阅 您需要在app.php文件中手动修改
Symfony\Component\HttpFoundation\Request:$httpMethodParameterOverride
布尔值:
protected function invalidate(Request $request, $catch = false)
{
$request->setMethod($request->request->get('_method'));
return parent::invalidate($request, $catch);
}
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();
此问题自symfony2.2之后出现,请参阅 您需要在app.php文件中手动修改
Symfony\Component\HttpFoundation\Request:$httpMethodParameterOverride
布尔值:
protected function invalidate(Request $request, $catch = false)
{
$request->setMethod($request->request->get('_method'));
return parent::invalidate($request, $catch);
}
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
Request::enableHttpMethodParameterOverride();
在连接缓存之前,一切正常。当我注释$kernel=newappcache($kernel)时;删除功能在连接缓存之前,一切正常。当我注释$kernel=newappcache($kernel)时;删除功能有效