使用学说2,我创建了我entities
的 inEntities
文件夹。
文件夹:
./
HelloEntity.php
WorldEntity.php
我在 PHP 中创建了我的结构并导入它们:
$namespaceYaml = array($connection->getBundle()->getNamespace() => $bundleFolder.'/Entity/ORM/');
$driver = new YamlDriver($namespaceYaml, '.orm.yml');
$path = $bundleFolder.'/Resource/config/doctrine/metadata/orm';
$config = Setup::createYAMLMetadataConfiguration(array($path), true);
$config->setEntityNamespaces(array($connection->getBundle()->getName() => $connection->getBundle()->getNamespace().'\Entity'));
$config->setMetadataDriverImpl($driver);
现在,它正在工作。我可以使用它们。
例如:
$qb = $this->getRepository()->createQueryBuilder('Hello'); //short here but long in from()
$qb->from('MyWeb\Entities\Hello', 'h'); //Hello Entity
现在,MyWeb
是我的主要根/命名空间。当我想在我的表格中使用学说时,我必须写MyWeb\Entities\Hello
. 我想做的就是缩短它们。我不能只用吗'Hello'
有谁有想法吗?