Speed symfony developing with eclipse snippets templates.
Eclipse Templates are a structured description of coding patterns that reoccur in source code.
Eclipse allows you to define templates for commonly used constructs, allowing you to insert them using the content assist tool (Ctrl+Space).
Even if Symfony successfully apply the Don’t Repeat Yourself (DRY) principle, many times, during developing, you have to write many times the same code snippet.
For example, select all record in a propel object:
$c = new Criteria();
$objects = PropelObjectPeer::doSelect($c);
In this article I would like to show you how to create Symfony code templates with Eclipse PDT.
Mauro Casula
Symfony-Framework.com
HOW TO CREATE A TEMPLATE:
- Click Window, Preferences..
- Select PHP from the list of preferences
- Select Templates..
- Click New.. and insert:
- Name ( how do you will call this template from code editing )
“doselect”
- Context: PHP
- A little description of the template:
“Criteria + doSelect costruct”
- Pattern:
$$c = new Criteria;
$$${objects} = ${propelObject}Peer::doSelect($$c);
- Now, edit a php file, write: “doselect” and press ( Ctrl+Space ).
This will write the costruct for you and put the cursor in the objects variable permiting you to modify the variable name.
- Modify the $objects variable name and press TAB.
This will move the cursor to the propel Object name permitting you to modify the value.
- Change the propel Object name as you desire… you have written a full costruct in few seconds.
MY SYMFONY ECLIPSE TEMPLATES
I wrote a group of eclipse symfony templates.
You can download the symfony-templates.zip file and import as follow:
- extract xml file from zip
- Click Window, Preferences..
- Select PHP from the list of preferences
- Select Templates and Click Import…
- Choose symfony-templates.xml file and accept.
From now, you can use these shorthand:
- action
public function execute${Action} {
${body}
}
- controller
class ${ControllerName}Actions extends sfActions {
public function execute${action}()
{
${body}
}}
- doselect
$$c = new Criteria;
$$${objects} = ${propelObject}Peer::doSelect($$c);
Any comment and suggestion will be agree.
Mauro Casula.
4 Responses to “Speed symfony developing with eclipse snippets templates.”
You can leave a response, or trackback from your own site.
Daniel
Said this at 7:08pm:Jeeez, I had no idea that works! That is AWESOME! My life will be filled with eclipse joy from now. Many thanks!
Juan Carlos
Said this at 8:27am:WOW.. What a beautiful tip!
Thank you very much.
Jc.
Tristan Rivoallan
Said this at 10:06am:Hi,
thanks for the post. maybe the templates could be shared in a more convenient way using http://www.symfony-project.org/snippets/ ?
that way more people could participate and comment on the template. Using an “eclipsetemplate” tag ?
regards,
tristan
Ronny
Said this at 1:43pm:Nice work… Never used those template function before.