[英]How to map doctrine entities
I want to adapt my folder structure to something similar: 我想调整我的文件夹结构类似的东西:
app
└─── ...
bin
└─── ...
src
└───MyNamespace
├───Application
│ ├───Controller
│ │ └───UserController.php
│ ├───Entity
│ │ └───User
│ │ ├───User.php
│ │ └───UserFactory.php
vendor
└─── ...
web
└─── ...
my config.yml file in the orm section looks like: 我在orm部分中的config.yml文件如下所示:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
user:
type: php
dir: %kernel.root_dir%/../src/MyNamespace/Application/Entity/User/User
prefix: MyNamespace\Application\Entity\User\User
alias: User
is_bundle: false
and my User.php file starts with: 我的User.php文件以:
namespace MyNamespace\Application\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table()
* @ORM\Entity
*/
class User
{
...
}
And then I get the: 然后我得到:
InvalidArgumentException: Specified non-existing directory "C:/www/myapp/app/../src/MyNamespace/Application/Entity/User/User" as Doctrine mapping source. InvalidArgumentException:指定的非现有目录“C:/ www / myapp / app /../ src / MyNamespace / Application / Entity / User / User”作为Doctrine映射源。
Btw, I'm using the Symfony2 framework. 顺便说一下,我正在使用Symfony2框架。
Grimv01k gave me the hint, but the final working solution were in the config.yml file with: Grimv01k给了我提示,但最终的工作解决方案是在config.yml文件中:
mappings:
user:
type: annotation
dir: %kernel.root_dir%/../src/MyNamespace/Application/Model/User
alias: 'User'
prefix: MyNamespace\Application\Model\User
is_bundle: false
that's it. 而已。 If I didn't change the mapping type to annotation, I've had the error "No mapping file found named 'MyNamespace.Application.Entity.User.User.php'" even having this file in my folder project structure.
如果我没有将映射类型更改为注释,我的错误是“找不到名为'MyNamespace.Application.Entity.User.User.php'的映射文件”,即使在我的文件夹项目结构中有此文件。 Still I didn't understand it, but it works now.
我仍然不理解它,但它现在有效。 Noob days... :)
Noob天...... :)
Well, I've got Entity
out of bundles, and config points only to entities source, like this: 好吧,我已经从捆绑包中获得了
Entity
,并且只将配置点指向实体源,如下所示:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
user:
type: php
dir: %kernel.root_dir%/../src/MyNamespace/Application/Entity
prefix: MyNamespace\Application\Entity
alias: Entity
is_bundle: false
Entity
dir should be a directory, so try to change dir
, prefix
and alias
settings. Entity
目录应该是一个目录,因此请尝试更改dir
, prefix
和alias
设置。 And than you actually can put subfolder User
in it and work with it by namespace. 并且实际上可以将子文件夹
User
放入其中并通过命名空间使用它。
By the way, you can read a great article about Symfony
structure customization. 顺便说一下,你可以阅读一篇关于
Symfony
结构定制的精彩文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.