开发者

Doctrine 2.0 ReflectionException when I try to do YAML Mapping

I have in my cli-config.php this code:

 $driverImpl = new \Doctrine\ORM\Mapping\Driver\YamlDriver(array(__DIR__.'/yaml'));
 $driverImpl->setFileExtension('.yml');
 $config->setMetadataDriverImpl($driverImpl);

In ./yaml there are the yml files (Client.yml,Worker.yml,Company.yml)

When i run the file to generate in db the schema with this instruccion:

php doctrine orm:schema-tool:create

throws:

PHP Warning:  class_parents(): Class Client does not exist and could not be loaded in applicationPath\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222

Warning: class_parents(): Class Cliente does not exist and could not be loaded in applicationPath\\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
PHP Warning:  array_reverse() e开发者_JS百科xpects parameter 1 to be array, boolean given in applicationPath\\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222

Warning: array_reverse() expects parameter 1 to be array, boolean given in applicationPath\\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
PHP Warning:  Invalid argument supplied for foreach() in applicationPath\\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222

Warning: Invalid argument supplied for foreach() in applicationPath\\system\application\libraries\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222



  [ReflectionException]
  Class Client does not exist

It´s the same that Doctrine documentation http://www.doctrine-project.org/docs/orm/2.0/en/reference/yaml-mapping.html

I don´t why it´s happening this, any idea? Thanks


IIRC, the SchemaTool will generate the SQL based on ClassMetadata instances, not directly from your YAML mappings. ClassMetadata instances require your actual entity classes as well

Make sure your command line tool has all your entity classes loaded/autoloaded.


I faced the same trouble. The trick is to generate entities from the yaml files with the --generate-annotations options set to 1. I've copied the command I used below :

$ doctrine orm:generate-entities --generate-annotations=1 Entities/

What this does is that it generates the entities along with all mapping information. Now if you change the Metadata driver config in your bootstrap to use the Entities instead of the yaml files the schema creation should work.

EDIT 2017-05-31 Revisiting this after a while. This looks like a case of Doctrine not being able to locate your "Class Client" due to autoloading issues. You could fix this by including the path to your bootstrap file / autoloader script in your cli-config.php .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜