symfonynerds.com

Nerds who love the symfony-project

Submit on Select Drop Down

Just a symfonynerds quick tip on getting a drop down select of names & URLs to submit when the userselects an item on it… One of those rare occasions when the first thing that came to mind seemed to work :)


<form action="<?php echo url_for('yesbar/submit') ?>" method="post">

<?php echo select_tag('links',objects_for_select($links, 'getLink', 'getName'), array("onchange" => "this.form.submit();")) ?>

</form>

  • 0 Comments
  • Filed under: 1.2, tip
  • The guys at UI Studio have done a really nice job of publishing http://symfony-check.org .

    It’s a simple site that goes through and helps you check if your symfony application is ready for deploymen. Be sure it check it out.


    A few weeks ago Symfony nerds launched the 2009 Symfony developers survey. It’s been great to get the communities feedback and today we are happy to publish the results. We had over 250 Symfony developers fill out the Developer Survey which was real exciting to see!.

    Some interesting highlights:

  • Most developers went straight from Symfony 1.0 to 1.2 and skipped 1.1
  • Propel is the dominant ORM framework, which is interesting in light of the recent announcement that Doctrine will be the default ORM framework in Symfony 1.3 and moving forward.
  • Ubuntu is by far the most popular platfrom Symfony developers choose to run their applications on
  • The question with the most evenly spread results is “How long have you been developing Symfony applications for” (see question 6). Indicating the community has a wide range of experience with lots of people under one year experience and many over two years experience.
  • Most Symfony developers have never developed in another web application framework
  • jQuery is by far the most popular library used with Symfony
  • Eclipse PDT is the most popular IDE for Symfony developers
  • No surprises here: Most Symfony developers are from Europe (which saddens us Aussies - we need more Aussie Symfony developers!)
  • There were no developers that took the survey indicated they run Symfony applications on Oracle and MSSQL. MySQL was the most popular database used by far.

  • 2009 Symfony Developers Survey Results



    1. What version of Symfony to you currently develop with the most?
    What version of Symfony to you currently develop with the most?

    1.0.* 18%
    1.1.* 6%
    1.2.* 76%



    2.What ORM Layer do you use the most?
    What ORM Layer do you use the most?

    Propel 67%
    Doctrine 31%
    Don’t use ORM 0%
    Other 2%



    3. Where do you ask your Symfony questions?
    Where do you ask your Symfony questions?
    People may select more than one checkbox, so percentages may add up to more than 100%.

    Official Symfony Forums 65%
    Symfony Blogs 23%
    Symfony Users Google Group 40%
    Symfony IRC Channel 19%
    External Training / Consultant 2%
    Other 14%



    4. What environment do you run most of your Symfony applications on?
    What environment do you run most of your Symfony applications on?

    Red Hat Linux 6%
    Ubuntu 39%
    Windows Server 8%
    Fedora 3%
    CentOS 8%
    Mac OS 7%
    Other *nix 13%
    Other 15%



    5. How do you install Symfony?
    How do you install Symfony?

    Pear Install 34%
    Source download 21%
    SVN checkout 40%
    SUSE package 0%
    Debian/Ubuntu package 1%
    Other 4%

    Most popular “other” value: SVN:Externals



    6. How long have you been developing Symfony applications for?
    How long have you been developing Symfony applications for?

    < 1 Year 29%
    1 Year 23%
    2 Years 21%
    2+ Years 28%



    7. What database do you use the most for your Symfony applications?
    What database do you use the most for your Symfony applications?

    MySQL 88%
    Oracle 0%
    PostgreSQL 10%
    MSSQL 0%
    DB2 0%
    SQLLite 2%
    Other 0%



    8. Have you (or do you) develop in other PHP Web Application Frameworks?
    Have you (or do you) develop in other PHP Web Application Frameworks?
    People may select more than one checkbox, so percentages may add up to more than 100%.

    CakePHP 15%
    Zend 30%
    Seagull 1%
    CodeIgniter 14%
    eZ Components 3%
    PRADO 2%
    Seagull Project 0%
    I have not developed in other frameworks 44%
    Other 15%

    Most popular “other” Smarty & “My Own”/”Custom Built” famework.



    9. Largest Symfony application you have built is used by…
    Largest Symfony application you have built is used by...

    less than 50 Users 26%
    less than 100 Users 6%
    less than 500 Users 17%
    less than 1,000 Users 8%
    less than 2,000 Users 6%
    greater than 2,000 Users 37%



    10. What types of application do you mostly build with Symfony?
    What types of application do you mostly build with Symfony?
    People may select more than one checkbox, so percentages may add up to more than 100%.

    CRUD Applications 76%
    SOA Based Apps (REST, SOAP…) 22%
    Integrated applications (mashups with existing systems) 32%
    Batch Processing Apps (Heaving focus on Tasks/Batch) 18%
    Workflow applications 38%
    eCommerce 29%
    Other 10%

    Popular responses for “other”: Online form-email, Intranets



    11. What other popular libraries do you use with Symfony?
    What other popular libraries do you use with Symfony?
    People may select more than one checkbox, so percentages may add up to more than 100%.

    Prototype 41%
    script.aculo.us 35%
    jQuery 77%
    jQuery UI 49%
    YUI (Yahoo! UI) 12%
    Adobe Flex 7%
    Other 8%

    Popular responses for “other”: ExtJS, MooTools & OpenLayers



    12. How do you contribute to the Symfony project?
    How do you contribute to the Symfony project?
    People may select more than one checkbox, so percentages may add up to more than 100%.

    I use Symfony 94%
    I am a Symfony Core Developer 3%
    I report bugs 39%
    I contribute to the symfony-developers group 12%
    I answer Symfony questions (IRC, Groups, Forums…) 43%
    I blog about Symfony 25%
    I am a plugin developer 23%
    I contribute to the Symfony Wiki 11%
    I contribute to the Symfony code Snippets 8%
    Other 5%

    Popular responses for “other”: Word of mouth / Sharing experiences with others.



    13. What IDE do you use when developing in Symfony?
    What IDE do you use when developing in Symfony?

    Eclipse + PDT 34%
    Eclipse 3%
    NetBeans 18%
    Komodo 2%
    PHP Designer 0%
    NuSphere PHPEd 2%
    Zend Studio 10%
    PHPEdit 0%
    My favourite text editor (Vi, Notepad, EditPlus…) 16%
    Other 15%

    Popular responses for “other”: Aptana, Coda, Dreamweaver



    14. Where do you develop Symfony projects from?
    Where do you develop Symfony projects from?

    Asia 7%
    Africa 2%
    North America 14%
    South America 6%
    Europe 71%
    Australia 2%
    Antarctica 0%



    15. If you had to choose one reason why you use Symfony, what would it be?
    If you had to choose one reason why you use Symfony, what would it be?

    Rapid Application Development (Admin Generator…) 27%
    Ease of use for front-end development (Ajax, Forms etc..) 9%
    Scalable Framework 16%
    Standards-based framework 24%
    Project Documentation 16%
    Quick to get started 4%
    Online Community 4%
    Training and Enterprise Support 0%
    Backed by an organisation 1%



    16. If you had to pick one area to improve the Symfony framework - what would it be?
    If you had to pick one area to improve the Symfony framework - what would it be?

    Simplify the Framework 14%
    Improve documentation 24%
    Additional features to the framework 8%
    Further work on the Admin Generator 13%
    Interoperability with other frameworks 3%
    Improved plugins 16%
    Focus on scalability 15%
    Other 6%

    Popular responses for “other”:
    - Lots of responses to stream line the Forms API (multiple ways of doing things), leading to confusion.
    - Focus on performance


    There you have it! Did anything surprise you? If you have any suggestions for next years survey, let us know! For those that missed out on filling out the survey, the survey is still open.

    Here at Symfony nerds we have been really excited to see the uptake of Symfony over the past few years. We thought we would create a Symfony Developers Survey.

    The purpose of this survey is to see how developers across the world are using Symfony. What areas of Symfony do you focus the most ? How do you think Symfony can be improved? These are the types of questions we ask. To take the survey, click on the link below.


    Take the 2009 Annual Symfony Developers Survey - Click here


    All results from this survey will be published on the site, with some nice (and pretty) graphs over the next couple of weeks. Thanks!

    This is a quick tip that will hopefully save you some time. The sfFormExtraPlugin is an excellent plugin with lots of extra features to help you build your forms. This tip is regarding the sfWidgetFormJQueryDate widget. This Widget lets you create a jQuery date selector. Setting up this widget is simple, but not well documented. Here are the basic steps of getting this started in your project forms:

    1. Install the sfFormExtraPlugin
    ./symfony symfony plugin:install sfFormExtraPlugin

    2. Install relevant jQuery libraries:
    a) Download jQuery AND
    b) Download jQueryUI

    3. Setup jQuery in your project
    Extract the JavaScript libs to your project js folder, then modify your app view.yml to include them:

    javascripts: [jquery-1.3.2.min.js, jquery-ui-1.7.1.custom.min.js]

    Note: The order in which the jQuery libs are included are important and can cause a conflict if they are not in the order above.

    4. Setup the CSS for jQuery UI
    When you download the jQuery UI, extract the smoothness theme into your web css directory. IE:

    /web/css/smoothness

    Now include the relevant CSS in your app view.yml:

    stylesheets: [main, smoothness/jquery-ui-1.7.1.custom.css]

    5. Setup the Widget your form class:
    Note in my example below, I will have an image icon as the date selector (/images/icons/calendar_view_month.gif). This is what the form class will look like:

    class myForm extends sfForm {
      public function configure()
      {
        $this->setWidgets(array(
          'from_date'    => new sfWidgetFormJQueryDate(array(
                 'image'=>'/images/icons/calendar_view_month.gif', 
                 'format' => '%day%/%month%/%year%')
                 ),
         //...other widgets
        ));
     
        $this->widgetSchema->setLabels(array(
      		'from_date'    => 'From Date',
                    //...other labels
        ));
      }
    }

    6. Display it in your view:
    Action:

      public function executeSearch(sfWebRequest $request){    
        $this->form = new myForm();
        return sfView::SUCCESS; 
      }

    View:

    ....
    echo $form['from_date']->renderLabel().":".$form['from_date'];
    ....

    And that’s it! You should get something looking like this:

    Hope this helps.

    In general, you will always run into issues trying to use the ‘/’ character as part of a parameter in your URL in web development. Recently I’ve run into issues trying to pass a parameter in my URL that has the forwardslash character. For example - trying to pass a URL within a URL:

    mymodule/myaction/url=http://google.com

    In the case above, Apache will return a 404 as it cannot find that URL (it things that http://google.com is part of the URL).

    This is a known issue that can be resolved in two ways:
    1) urlencode() + ApacheEncodedSlashes
    You could use urlencode() to escape your http:// slashes, and then change you’re ApacheEncodedSlashes directive to allow this (further reading). However this does require a Apache change.

    2) The quick fix is to simply tell Apache that it is a parameter, not part of the URL, by changing the / to a ?
    mymodule/myaction?url=http://google.com

    This works fine. However, in Symfony you can’t get this to work if you are trying to use the link_to_remote Ajax Helper function.

    The following code:

    $url = "http://google.com";
    echo link_to_remote($topic->getName(), array(
      'update'   => array('success' => 'topic_detail', 'failure' => 'topic_detail_err'),
      'url'      => "mymodule/myaction?t="$url,
      'script'   => 'true',
      'loading'  => visual_effect('appear', 'loading_animation'),
      'complete' => visual_effect('appear', 'topic_detail')
    ));

    Will produce this URL:

    ....mymodule/myaction/url=http://google.com

    Notice that Symfony converts the ? to a /. This is because we are using link_to_remote. link_to_remote goes through the routing layer that converts all ? to / characters. If we were using url_for, this would not be an issue.

    So how do we overcome this problem if we are using link_to_remote? Well it’s simple - use both the Symfony url_for() helper function as well as the PHP http_build_query function. The http_build_query function encodes the URL for us (so ‘/’ get converted to %2F, alongside other characters).

    So the end result looks like this:

    $url=  url_for("mymodlue/myaction")."?".http_build_query(Array("t"=>$topic->getName()));
    echo link_to_remote($topic->getName(), array(
      'update'   => array('success' => 'topic_detail', 'failure' => 'topic_detail_err'),
       'url'      => $url,
       'script'   => 'true',
       'loading'  => visual_effect('appear', 'loading_animation'),
       'complete' => visual_effect('appear', 'topic_detail')
    ));

    This forces link_to_remote to use the ? instead of replacing it with a /. Hope this helps!

    Symfony 2! A sneak peak

    Fabian has recently posted a presentation he has given on Symfony 2.0.

    The framework has undergone a complete overall making it faster and light-weight. Checkout all the details of Symfony 2.0 here.

    If you are defining your schema.yml and have a field that is a decimal value, you will find you will need to somehow pass through the precision (maximum number of digits to the left of the point) and the scale (total number after the decimal point). The documentation for the syntax of this is quite poor.
    For all those that want to know, in Symfony 1.0 this is how you would define a decimal:

    my_decimal: { type: decimal, size: 8,3 }

    For Symfony 1.1+, the Syntax is a bit different:

    my_decimal:
          type: decimal
            size:    8
            scale:   3

    Where 8 is the precision and 3 is the scale. Hope this helps.

    Symfony application configuration can be configured for each application in the app.yml file. One of they key problems with this is if you want an end-user to be able to change some of this application configuration, they can’t. You would need to do that for them.

    A good way to fix this is to store your applications configuration in the database. This comes with a performance cost (extra calls to your database) - so its up to you to decide if this is the most efficient solution for you.

    Here is an outline on how to get started building your application’s config in the database.

    Step 1: Define your model
    Create the columns you want to store for your application config. In this instance, we are just going to store name and value pairs (ie Attribute & Value). Here is a sample below:

    propel:
      #Application configuration table
      my_app_config:
        _attributes:                { phpName: MyAppConfig }
        id:                         { type: integer, required: true, primaryKey: true, autoIncrement: true }
        attribute:                  { type: varchar(255) }
        value:                      { type: varchar(255) }
    ...

    Once you have finished that, go ahead and build your model

    Step 2: Extend Your MyAppConfig class
    So the next step is for us to make it easy to access application configuration. For us to do this, go to your lib/model/MyAppConfig.class.php and extend your base class as follows:

    <?php
    class MyAppConfig extends BaseMyAppConfig
    {
     
      /**
       * Returns a value of an attribute string for my app's config table
       * @param string attribute name
       * @return string The value of that attribute
       * @author eHabib
       */
    	public function lookupValueFromAttribute($attribute){
      		$c = new Criteria();
      		$c->add(MyAppConfigPeer::ATTRIBUTE, $attribute);
      		$result = new MyAppConfig();
      		$result = MyAppConfig::doSelectOne($c);
    		return ($result->getValue());
    	}
    }

    Step 3: Use it!
    Let’s say that in our database we have the following attribute/value paris:

    Attribute: app_support_email, Value: myemail@mydomain.com
    Attribute: app_base_url, Value: http://whatever

    You could access this data in your code by doing this:

    $myConfig = new MyAppConfig();
    $appEmail = $smyConfig->lookupValueFromAttribute("app_support_email");
    $appURL = $smyConfig->lookupValueFromAttribute("app_base_url");
    ...
    echo $appEmail.",".$appURL; //lets print it

    That’s it!

    Step 4: Configure it via your front-end
    The last step (if you wish) is to allow the end-user to update the value of these fields. To do this, you can build a form to update these fields, or use Symfony’s admin generator.

    One of the things that might not be clear to Symfony developers is when to use app.yml for your application config and when to use project-level configuration for all your applications.

    If your configuration parameter is for all your applications you should place this configuration setting within your config/ProjectConfiguration.class.php (Symfony 1.2.x). This will save you duplicating the config within each app’s app.yml and you only have to specify it once.

    Setting up project-level config
    You can set project-wide config by editing this file.

    ....
    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        //In my example below I want to tell my app if it should use a proxy or not 
        sfConfig::set('use_proxy', '1');	//1 = True, 0=False
        $this->enableAllPluginsExcept(array('sfDoctrinePlugin', 'sfCompat10Plugin'));
      }
    }

    Anything you place in your project-level config can be accessed from any application (or Symfony task) by using the standard sfConfig::get() static method.

    Note: You would normally have to get the application context if you want to read an application config within a Symfony Task. In this case, you wouldn’t because the config is set at a project level.