Tag Archive for 'symfony'

observe_field in symfony and it’s options

While looking for possible options for the observe_field() helper in symfony, I noticed there wasn’t a lot of documentation around to describe what the possible options are to pass to it. After a bit of searching, I found what I wanted and thought I’d share it in case someone else would need a similar thing:

        < ?php echo object_input_tag($server, 'getMainIp') ?>
        <div id="valid_ip"></div>
        < ?php echo observe_field('main_ip', array(
                'url' => '@lookup_ip',
                'frequency' => 3,
                'update' => 'valid_ip',
                'with' => "'ip='+$('main_ip').value",
                'loading' => "Element.show('indicator')",
                'complete' => "Element.hide('indicator');"
        )) ?>
        <div id="indicator" style="display:none"></div>

I needed to create an input field for an IP. If you want to change the IP, a request should be made to check if the IP is still available or not.

What this basically does is check if the field 'main_ip' (this is the object_input_tag() field) changes, and it does that every 3 seconds. If it has changed, we go to the url '@lookup_ip' and pass it one parameter, named ‘ip’ with the value of the input field we are observing. During loading the request, we show an indicator that we’re loading in the background, and if the request is complete, the indicator is hidden and the div 'valid_ip' is filled with the output of our action.

Pretty easy if you have a look at the code, but there aren’t much docs around that give examples for this. A good resource for these things is the Symfony JS and Ajax cheat sheet you can find here. (I chose the english version ;))

PHP Abstract podcast about Symfony

 PHPAbstract has a cool podcast up about the symfony framework. This is presented by Stefan Koopmanschap, web application developer at Ibuildings.nl.

His podcast is a brief introduction to symfony, what programming principles it uses, why it can be an advantage for you to deploy your project with symfony and more. A brief and interesting introduction talk to symfony.

The link to the podcast can be found here.

Installing symfony in a subdirectory of your documentroot

I recently needed to set up a Symfony install without a separate virtual host, so as a subdirectory of the (Apache) DocumentRoot directory (like: http://www.example.com/symfony/).

As you may know, symfony appreciates it when it has a reserved virtual host for itself, but also provides ways to just install it in a separate directory. The following steps need to be taken:

1. Change the apps/<yourapp>/config/settings.yml file and set relative_url_root

    relative_url_root: /subdir

2. Go to your front controller’s .htaccess file (usually in web/) and modify the RewriteBase directive

RewriteBase /subdir/

3. Optionally, if you want to omit the script name in production environment url’s, be sure to have enabled no_script_name = on in apps/<yourapp>/config/settings.yml

    no_script_name: on

4. If you took step 3, be sure to check if your apache installation has support for mod_rewrite enabled.

This way you can have nice url’s, like http://www.example/subdir/module/action
That’s it!