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:
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:
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.
Btw, I'm using the Symfony2 framework.
Grimv01k gave me the hint, but the final working solution were in the config.yml file with:
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. Still I didn't understand it, but it works now. Noob days... :)
Well, I've got Entity
out of bundles, and config points only to entities source, like this:
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. And than you actually can put subfolder User
in it and work with it by namespace.
By the way, you can read a great article about Symfony
structure customization.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.