|
|
Attenzione!Sembra che un programma di rimozione della pubblicità come AdBlock sia attivo. CoolSoft si accontenta di un paio di banner non fastidiosi e nessun popup. Grazie per l'aiuto. |
![]() |
How to make Symfony/Doctrine generate accessors
I'm using Symfony for a big project; after a little research I choosed Doctrine as database access layer, since is more configurable (and modern) then Propel.
I use Eclipse 3.4 and PDT as IDE, mostly because of its great Code Assist feature (CA is Intellisense for VisualStudio users...).
Well, after a bit I found that Doctrine class generator misses to generate column accessors (getters and setters) and relies on PHP __get and __set magic accessors.
Suppose you have an user table, Doctrine generates an User class for you and you can access columns of a single record through its properties, like this:
$a = new User(); $a = $user->getUsername(); $user->setUsername('foo');
Since getUsername() and setUsername() are not real properties, Doctrine lets you access them through __get and __set.
Even if this works, IDEs like Eclipse can't help you writing code because they don't know what properties are defined on User class (except the ones of the class it extends, but they are generic and not related to users table).
Searching through Doctrine documentation, it seems that there should be a generateAccessor option of Doctrine builder which should do the trick; you'll quickly find that this option only exists but is not implemented.
Here you are my solution: a patch for Doctrine builder to add missing accessors generator.
Download the attached file and overwrite the existing one here:
/lib/symfony/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Builder.php
NOTE: this patch applies to Doctrine builder included in both Symfony 1.2.2 and Symfony 1.2.4 version.
Feel free to comment my patch...
| Attachment | Size |
|---|---|
| Symfony_1_2_2_Doctrine_Builder_patch.zip | 7.22 KB |



Comments
Accessors Appears to be officially implemented in 1.1
Method buildAccessors()
Method buildAccessors() existed in version 1.0, and it was not invoked too.
My patch not only calls it, but extends its implementation adding type declaration through PhpDoc, which is great in IDEs like Eclipse.
I'll give a try to 1.1 soon and I hope they extended its implementation and call it.
Greate, thanks
Zend studio for eclipse 7 autocomplete model class correctly.
Shame that symfony does not implement natively option generate_accessors.
You're welcome. I agree about
You're welcome.
I agree about the shame on Doctrine/Symphony :D
How to use?
I usually run this...
I usually run this from command line:
$ symfony doctrine:build-model
This should overwrite all your model files into /lib/model/doctrine/base/*
Just to be sure, you could rename/move this folder content before running the above command...