我已经成功安装和设置了 Symfony 2,并且一直在遵循文档。
我目前正在做http://symfony.com/doc/2.0/book/doctrine.html http://symfony.com/doc/2.0/book/doctrine.html
一切都很好,直到我到达这一行:
php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Product
此时我收到以下错误:
[RuntimeException]
The autoloader expected class "Acme\StoreBundle\Entity\Product" to be defined
in file "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Symf
ony\app/../src\Acme\StoreBundle\Entity\Product.php". The file was found but the
class was not in it, the class name or namespace probably has a typo.
我在 Linux 和 Windows 机器上都发生过这种情况。
Product.php 的内容按照教程:
// src/Acme/StoreBundle/Entity/Product.php
namespace Acme\StoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100)
*/
protected $name;
/**
* @ORM\Column(type="decimal", scale=2)
*/
protected $price;
/**
* @ORM\Column(type="text")
*/
protected $description;
}
该消息来自 DebugUniversalClassLoader.php:
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false)) {
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
}
因此,该文件必须存在并且可读,否则findFile
和require
是行不通的。所有这些检查正在做的是require()
解析该文件,然后使用标准 PHP类存在 http://php.net/manual/en/function.class-exists.php() 查看该类现在是否存在。
考虑到这些文件内容,我唯一能想到的可能会导致此消息:您错过了<?php
在文件的开头。现在,我知道这有点危险,但老实说,我想不出还有什么不会导致其他类型的错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)