Posts Tagged snippet

Symfony Template and Component Templates

Today I’ve got a pair of small templates.

The first is a comment header for the Symfony template files.  Due to the shear number of these template files you can create if you’re partial and component happy, sometimes just the filename isn’t enough to really describe what file your editing. My motto is you can never have too much documentation.

1
2
3
4
5
6
7
8
9
10
11
<?php
/**
 * Template Template
 * 
 * @author Phazeon Phoenix <phoenix@phazeon.com>
 * @version 1
 * @package Templates
 * @copyright 2009 Phazeon.com
 */
?>
<h2>My Template</h2>

Next is a template for new components.  This is the sort of thing that I always had trouble remembering. I had to track down the exact syntax for the component class declaration each time.  Now in my IDE (phpDesigner) I can define user entered variables in my snippets/templates.  It prompts me for the model name and the method name minus the “execute” prefix.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
 * Component Template
 * 
 * @author Phazeon Phoenix <phoenix@phazeon.com>
 * @version 1
 * @package Components
 * @copyright 2009 Phazeon.com
 */
 
class templateComponents extends sfComponents
{
    public function executeSomething()
    {
 
    }
}

, , , , ,

No Comments

Symfony 1.1+ Form Template

In my work with Symfony I’ve started collecting a library of code snippets that I use to speed up my creation of different objects in the Symfony tree. Since most of them are cut and splices of other people’s code (especially the Symfony documentation) I’m going to start posting some of the better ones on my blog.

The one that I’m going to share today involves the creation of a form class for the new form handling classes added in Symfony 1.1.  I found myself constantly having to go back to the form and adding the sections that I needed but forgot the list time I was working it. I created this template and included all of the options I felt I’d need to declare to correctly implement a nice looking and behaving form.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
 * Template Form
 * 
 * @author Phazeon Phoenix <phoenix@phazeon.com>
 * @version 1
 * @copyright 2009 Phazeon.com
 * @package Forms
 */
class templateForm extends sfForm
{
    public function configure()
    {
        $this->setWidgets(array(
 
        ));
 
        $this->setValidators(array(
 
        ));
 
        $this->setDefaults(array(
 
        ));
 
        $this->widgetSchema->setLabels(array(
 
        ));
 
        $this->widgetSchema->setFormFormatterName('list');
 
        $this->widgetSchema->setNameFormat('template[%s]');
    }
}

, , , , ,

1 Comment