我使用symfony 2.3框架,自动加载程序声称找到了文件,但没有找到类:
RuntimeException: The autoloader expected class "SensioBundle
FrameworkExtraBundleRequestParamConverterDateTimeParamConverter"
to be defined in file "/home/na/auth/vendor/sensio/framework-extra-bundle/
Sensio/Bundle/FrameworkExtraBundle/Request/ParamConverter/
DateTimeParamConverter.php". The file was found but the class was not in it,
the class name or namespace probably has a typo.
所指的文件如下所示:
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace SensioBundleFrameworkExtraBundleRequestParamConverter;
use SensioBundleFrameworkExtraBundleConfigurationConfigurationInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpKernelExceptionNotFoundHttpException;
use DateTime;
/**
* Convert DateTime instances from request attribute variable.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class DateTimeParamConverter implements ParamConverterInterface
{
/**
* @{inheritdoc}
*
* @throws NotFoundHttpException When invalid date given
*/
public function apply(Request $request, ConfigurationInterface $configuration)
{
$param = $configuration->getName();
if (!$request->attributes->has($param)) {
return false;
}
$options = $configuration->getOptions();
$value = $request->attributes->get($param);
$date = isset($options['format'])
? DateTime::createFromFormat($options['format'], $value)
: new DateTime($value);
if (!$date) {
throw new NotFoundHttpException('Invalid date given.');
}
$request->attributes->set($param, $date);
return true;
}
/**
* @{inheritdoc}
*/
public function supports(ConfigurationInterface $configuration)
{
if (null === $configuration->getClass()) {
return false;
}
return "DateTime" === $configuration->getClass();
}
}
无论如何,一些细节可能会有所帮助,我最近安装了Doctrine并运行了命令…
2028 php app/console doctrine:schema:create
2029 php app/console doctrine:generate:entities Auth
执行完这些命令后,symfony停止工作。我不知道这是什么奇怪的虫子还是什么。如果你需要更多的信息,我可以贴出来。谢谢你的帮助。
缺少(或短)PHP开始标记也会导致该错误。是的,这听起来很有趣,但如果你只是遵循Symfony的例子并复制/粘贴整个类,你可能不会注意到这一点(就像我一样)。
这个有点老了,但是如果有人通过搜索找到这里:这无疑是一个缓存问题。手动删除app/cache/dev和app/cache/prod的内容,一切都应该解决。
如果其他人也有这个问题,并且它不会通过清除缓存而消失,那么我建议删除整个文件夹与您的编写器依赖并重新执行composer install
。
我想Symfony2有一个bug。他们最近更新到symfony的新版本(2.3.1),我想这一定是坏了什么。无论如何,我不得不在AppKernel.php文件中注释出//new SensioBundle frameworkextrabundance sensioframeworkextrabundance()行以消除错误。
确保您的名称空间是在您尝试使用的类中定义的。例如,在控制器中,我输入:
use AcmeDemoBundleAmazonAmazonProductAPI;
这是我的AmazonProductAPI类的正确路径,但是直到我向该类添加了适当的名称空间之后,系统才识别出它:
namespace AcmeDemoBundleAmazon;
@MilanG的回答帮了我!我将PHP配置从
short_open_tag = Off
short_open_tag = On
我通过在Doctrine
之前删除额外的来解决这个问题,如:
<entity repository-class="ACCBundleMGLBundle\DoctrineORMPersonRepository"
name="ACCBundleMGLBundleEntityPerson" >`
我使用generate:doctrine:entity
实用程序来创建实体和orm.xml
文件。这个实用程序似乎有一个bug,它在上面的xml文件中添加了一个额外的。删除这个额外的反斜杠
解决了我的问题。因此,在使用命令
php app/console doctrine:generate:entity
之后检查orm.xml
文件,以确保路径中没有额外的反斜杠。这个错误可能在Symfony的后续版本中已经解决了,但如果您遇到这个错误,这可能是原因。
在我的例子中,它是类名中的错别字。当类名被命名为AsssetsCommand
时,我在AssetsCommand.php
中得到了一个错误
确保类文件的基名与类名相同。
觉得我看到的每个答案都能解决问题,但事实并非如此。在我的例子中,它最终是OpCache。忘了我在开发过程中打开了它。解决方案是每次对代码库进行更改时重新启动PHP-FPM或Httpd(当使用mod_php时),或者完全禁用OpCache。
当我声明错误的命名空间时,就会发生这种情况。
示例:命名空间AppBundleController;
,但类在这个路径:AppBundleRestController
如果这个错误弹出,您应该检查您的文件名是否有拼写错误。然而,在我的例子中,它说"找到了文件,但类不在其中,"类名或命名空间可能有拼写错误",实际上文件名不正确("From"而不是"Form")