我開始在 silex 中使用帶有來自文檔的簡單注釋的學說@Entity并且它起作用了?,F在我看到 symfony 使用 importuse Doctrine\ORM\Mapping as ORM;和@ORM\Entity. 但是當我添加這個時,學說會拋出一個錯誤 Class "App\Entity\Author" is not a valid entity or mapped super class.namespace App\Entity;use App\Helpers\Jsonable;use App\Helpers\MassAssignable;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\AuthorRepository") * @ORM\Table(name="authors") */class Author{ use MassAssignable; use Jsonable; /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @var int */ protected $id; /** * @ORM\Column(type="string") * @var string */ protected $name;我的配置沒有額外的選項$config = Setup::createAnnotationMetadataConfiguration([ __DIR__.'/../src/Entity/']);$app['db.em'] = EntityManager::create($app['db'], $config);
1 回答

浮云間
TA貢獻1829條經驗 獲得超4個贊
您正在使用SimpleAnnotationReaderwhich 無法從非直接導入的命名空間加載注釋。您可以通過false為元數據配置傳遞第 5 個參數來輕松切換。
public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null, $useSimpleAnnotationReader = true)
所以在你的情況下:
$config = Setup::createAnnotationMetadataConfiguration(
[__DIR__.'/../src/Entity/'],
false,
null,
null,
false
]);
- 1 回答
- 0 關注
- 159 瀏覽
添加回答
舉報
0/150
提交
取消