Jun3

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.

  1. Jun3

    Daniel

    Said this at 7:08pm:

    Jeeez, I had no idea that works! That is AWESOME! :D My life will be filled with eclipse joy from now. Many thanks!

  2. Jun4

    Juan Carlos

    Said this at 8:27am:

    WOW.. What a beautiful tip!

    :)

    Thank you very much.

    Jc.

  3. Jun4

    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

  4. Jun5

    Ronny

    Said this at 1:43pm:

    Nice work… Never used those template function before.

 

Leave a Reply

 

Recent Posts

Popular Categories

No categories

About

We are a group of programmers with the passion of Object Oriented Programming and PHP5… We hope to help the Symfony comunity to grow, we hope to help Php programmers to switch to MVC world and we wish you can find in this blog all you answers… Welcome to Symfony-Framework.com.

<<The Administrators>>