Le 04/09/2014 16:05, Sebastian Brandner a écrit :
Hi!

I don't relly like the usage of strings when the same value is used all over the project. To write 100x 'MyNamespace\Model\MyEntity' is quite bad if you want to refactor things some times.

From doctrine manual:

|
$user =$em->find('MyProject\Domain\User',$id);
|


From symfony manual:

|
$repository =$this->getDoctrine()->getRepository('AcmeStoreBundle:Product');

Aslongasyour entity lives under the Entitynamespaceof your bundle,thiswill work.
|


My best idea is to implement a constant and use this when requesting a repository.

|
namespaceMyNamespace;

classMyEntity{
constENTITY_NAME =__CLASS__;
}
|

and then call

|
$this->getDoctrine()->getRepository(MyNamespace\MyEntity::ENTITY_NAME);
|

With this construct I'm able to refactor the classes because the MyNamespace\MyEntitywill be updated or will be invalid.

    /Another possiblity would be a trait with "public static function
    entityName() { return __CLASS__; }" and use this in every entity,
    but i think this is the same solution. :) /




Does anyone have a better idea?



Use PHP 5.5, which allows to use |MyNamespace\MyEntity::class for any class
|

--
Christophe | Stof

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to