Symfony Cache Validation error: Cannot declare class Response after using setPublic()
Symfony Cache Validation error: Cannot declare class Response after using setPublic()
我在玩HTTP Cache Validation - Validation with the ETag Header
在我的控制器中我有:
// ... get the $data and $myObject somehow ...
$response = $this->json($data);
$response->setEtag($myObject->getDateModified()->format("Y-m-d H:i:s")); // getDateModified() returns a DateTime
$response->setPublic();
return $response;
删除缓存后第一次加载页面,控制器是运行,一切正常。但是从第二次开始我只得到:
FatalErrorException in classes.php line 3353: Error: Cannot declare
class Symfony\Component\HttpFoundation\Response, because the name is
already in use
一用就出现这个问题$response->setPublic();
导致问题的原因是什么?我做错了什么吗?
我找到了这个,也许对你有帮助https://github.com/contao/core-bundle/issues/643
他们建议从 app.php
中删除行 $kernel->loadClassCache();
。
It is a speedup attempt which preloads classes which are needed in
most requests. This is however obsolete in PHP7.0 and marginal in PHP
5.6 - therefore it is save to remove it.
编辑:我删除了第 $kernel->loadClassCache();
行,不再有错误,http 缓存工作正常。
此外,这里还有额外信息:https://github.com/symfony/symfony/issues/20668
我在玩HTTP Cache Validation - Validation with the ETag Header
在我的控制器中我有:
// ... get the $data and $myObject somehow ...
$response = $this->json($data);
$response->setEtag($myObject->getDateModified()->format("Y-m-d H:i:s")); // getDateModified() returns a DateTime
$response->setPublic();
return $response;
删除缓存后第一次加载页面,控制器是运行,一切正常。但是从第二次开始我只得到:
FatalErrorException in classes.php line 3353: Error: Cannot declare class Symfony\Component\HttpFoundation\Response, because the name is already in use
一用就出现这个问题$response->setPublic();
导致问题的原因是什么?我做错了什么吗?
我找到了这个,也许对你有帮助https://github.com/contao/core-bundle/issues/643
他们建议从 app.php
中删除行 $kernel->loadClassCache();
。
It is a speedup attempt which preloads classes which are needed in most requests. This is however obsolete in PHP7.0 and marginal in PHP 5.6 - therefore it is save to remove it.
编辑:我删除了第 $kernel->loadClassCache();
行,不再有错误,http 缓存工作正常。
此外,这里还有额外信息:https://github.com/symfony/symfony/issues/20668