How to Create Symfony Plugin – sfNiceFormsPlugin

Sharing is caring!

I am a symfony fans since long time ago and love the way it works, so i have developed a lot of website using this awesome php framework. Anyway, few days ago i just came across my mind, i should go through the symfony plugin development process and write it down in order to share with everyone, so i do some research on web and say to myself “Let’s Do It!”.

First, i go through some reference sites that are important for my plugin development process:

In order to start developing a plugin for symfony, it’s very important to understand the structure of the plugin.

Symfony Plugin Architecture
Symfony Plugin Architecture (source from

sfNicerFormsPlugin, i am ready to start with this Niceforms v2.0 project by Lucian Slatineanu which is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

sfNiceFormsPlugin filestructure as below:

lib/ helper/ web/ css/ custom/ default/ images/ custom/ default/ js/ default/ custom/ LICENSE README

NiceFormsHelper.php is the main file to render the form with a new tag definied here – ‘niceforms_form_tag()‘ that is modified version of form_tag(). Let’s have a look at the code below:

'hidden', 'name' => 'sf_method', 'value' => $html_options['method'])); $html_options['method'] = 'post'; } return tag('form', $html_options, true).$html; } function load_niceforms_theme() { $niceforms_theme = sfConfig::get('app_niceforms_theme'); switch($niceforms_theme) { case 'default': sfContext::getInstance()->getResponse()->addJavascript('/sfNiceformsPlugin/js/default/niceforms'); sfContext::getInstance()->getResponse()->addStylesheet('/sfNiceformsPlugin/css/default/niceforms'); break; case 'custom': sfContext::getInstance()->getResponse()->addJavascript('/sfNiceformsPlugin/js/custom/niceforms'); sfContext::getInstance()->getResponse()->addStylesheet('/sfNiceformsPlugin/css/custom/niceforms'); break; default: sfContext::getInstance()->getResponse()->addJavascript('/sfNiceformsPlugin/js/default/niceforms'); sfContext::getInstance()->getResponse()->addStylesheet('/sfNiceformsPlugin/css/default/niceforms'); } } ?>

After this, you need to create README file and put the instructions on how to use the plugin. Please use this Markdown dingus plugin to check your content in README before proceed.

sfNiceFormsPlugin plugin ========================== sfNiceFormsPlugin is a symfony plugin that provides the NiceForms form render based on the [NiceForms 2.0 javascript library]( NiceForms v2, a non-intrusive javascript method that allows complete customization of web forms. Installation ------------ * Install the plugin $ symfony plugin:install sfNiceFormsPlugin * Install assets $ symfony plugin:publish-assets * Clear the cache $ symfony cache:clear Documentation ------------- * Set the theme `app.yml`: all: niceforms: theme: "default" # 2 themes available now : "default" & "custom" * Declare the helper * To implement niceform form tag 'myform', 'name' => 'myform')) ?> Make Your Own Theme -------------------- * Open the default.psd in sfNiceFormsPlugin/web/images folder, design the field elements base on your need * Click File -> Save For Web & Devices, choose PNG-24, click 'Save' and select file type as 'HTML and Images' * Replace all identical png files into sfNiceFormsPlugin/web/images/custom/ and you can use your own custom theme now by setting app.yml theme option to 'custom'.

Once the symfony plugin files are ready, you need to make package.xml at the root level of plugin directory and package.xml file must follow the PEAR package.xml 2.0 documentation.

There are 2 ways to generate package.xml

sfNiceFormsPlugins package.xml:

sfNiceFormsPlugin NiceForms v2.0 - a non-intrusive javascript method that allows complete customization of web forms a symfony plugin to implement Niceforms v2.0 from Lucian Slatineanu ( Terry Tsang terrytsang yes 2011-05-18 00:28:36 1.0.1 1.0.0 stable stable MIT license - 5.2.4 1.4.1 symfony 1.3.0 1.5.0 1.5.0 1.0.1 1.0.0 stable stable MIT license 2011-05-18 MIT * terrytsang: fixed README

Once the package.xml is done, it’s time to pear package the plugin so that you can upload the PEAR package to the plugins Admin form after u have create the plugin in symfony page.


Try to run this command in order to avoid any error in pear package:

pear channel-update

The command to run in the folder sfNiceFormsPlugin in order to generate sfNiceFormsPlugin-1.0.1.tgz

pear package

If you are using sfTaskExtraPlugin, you can run this command to create a plugin PEAR package:

symfony plugin:package sfNiceFormsPlugin

Hope this tutorial will be the tips for anyone who likes to have their own symfony plugin. Cheers!

3 thoughts on “How to Create Symfony Plugin – sfNiceFormsPlugin”

  1. You’ve got posted some decent stuff over the matter, are you currently working to participate in a FAQ regarding this theme sooner or later, because have some more questions which is present with other readers. Choose Makeup Foundation.

Leave a Comment

Your email address will not be published. Required fields are marked *