我已经成功安装和设置了Symfony 2并且一直在关注文档.
我目前正在访问http://symfony.com/doc/2.0/book/doctrine.html
一切都很好,直到我到达这一行:
php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Product
Run Code Online (Sandbox Code Playgroud)
此时我收到以下错误:
[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.
Run Code Online (Sandbox Code Playgroud)
在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;
}
Run Code Online (Sandbox Code Playgroud)
Mat*_*son 25
该消息来自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));
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,该文件必须在那里,和可读性,否则,findFile和require不会奏效.所有这些检查都在做require()文件,然后使用标准的PHP class_exists()来查看该类是否在那里.
我能想到的唯一一件事可能会导致这些消息给出这些文件内容:你错过<?php了文件的开头.现在,我知道这有点不合时宜,但老实说,我不能想到任何其他不会引起其他错误的事情.
| 归档时间: |
|
| 查看次数: |
7624 次 |
| 最近记录: |