Ocramius / ocramius.github.com

:books: Coding thoughts and ideas by Ocramius
https://ocramius.github.io/
40 stars 25 forks source link

Class User not found #9

Closed ghunti closed 11 years ago

ghunti commented 11 years ago

I Marco.

I've been following your presentation http://marco-pivetta.com/doctrine-orm-zf2-tutorial, but when I'm on the controller, and I write

$user1 = $objectManager->find('User', 1);

like you have on http://marco-pivetta.com/doctrine-orm-zf2-tutorial/#/27/3, I keep getting an "Class User does not exist" error.

The only way to fix this is to use full entity path like:

$user1 = $objectManager->find('Application\Entity\User', 1);

I don't know if that is the only valid way, but if it is, another concern is raised. If Im building module Application and latter on I want another module to override its entities, then the doctrine module will keep using Application entities since I've provided full path correct?

Thanks, Gonçalo

Ocramius commented 11 years ago

Ah, yes. It's correct, Application\Entity\User is what you have to use (when in string context, you always use the FQCN). Can you PR against my slides?

Ocramius commented 11 years ago

You can also override mappings by rewriting metadata, but that's not a good approach. What you can do is having the entity name configurable somewhere.

Ocramius commented 11 years ago

Closing, see Ocramius/doctrine-orm-zf2-tutorial#10

ghunti commented 11 years ago

I've committed a PR. One other thing, why do we configure doctrine.driver.application_entities.paths if then we need to specify FQCN?

Thanks, Gonçalo

Ocramius commented 11 years ago

@ghunti that's because the annotation driver scans specific directories for entities. Otherwise, it would have to scan the entire app - could you imagine that? ;)

ghunti commented 11 years ago

Thanks. It makes sense ;-)