Nerds who love the symfony-project
23 Apr
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!
7 Feb
For a while now Symfony developers have been looking for a good IDE to use when developing in the Symfony framework. Some use Eclipse with PDT (PHP Development Toolkit), some use NetBeans 6.5 with it’s recent support of the PHP stack, some have tried creating Symfony-specific Eclipse plugins, without much sucess and many often prefer to use their favorite text editor.
Whatever you choose, it’s great news to see that Sun is going to back Symfony specific things in its upcoming release of NetBeans 7.0 - the framework is maturing and so are its tools.
For a while now, NetBeans have been evaulating the support of a PHP framework within it’s stack. A call out went to Symfony developers, to vote if you want it!. NetBeans thenĀ began evalutating the big response it got from Symfony developers.
Not sure if it missed most peoples radar (it missed ours!) - but late last year, Sun announced Symfony will be supported as part of NetBeans 7.0:
“The news is that the Symfony support will be part of NetBeans 7.0. We are going to start work on it very soon. I hope that it will be a part of continual build this year and community can comment the support and work with us to finish it in the best possible quality and usability”
From what we can tell from here and the product Roadmap, NetBeans 7.0 release could be ready somewhere between April and June this year.
Do you use an IDE when developing in Symfony? What do you use? Do you think you will use NetBeans 7.0? Let us know… interested to hear your thoughts…
20 Oct
A few of us here at Symfony Nerds get together to record a Tech podcast every now and then and talk about nerdy stuff. The podcast is called Instantiate Podcast.
This week we recorded our third episode where we talked about Enterprise Micro-blogging and web development frameworks. For anyone out there that is thinking of using Symfony, or looking at using a web development framework, checkout Episode 3. We talked about Frameworks and Symfony in some detail, here is what you will hear:
Have a listen to Instantiate Podcast - Episode 3 at the Instantiate Podcast website, or subscribe to the podcast in iTunes or RSS.
11 Oct
If you are looking for a way to distribute your Symfony application - either as a deployment package, to host on another server without Symfony libs, or giving it out as a product you could always use the Symfony sandbox to do so. However, this becomes hard to maintain when Symfony versions keep getting updated, and you have to keep your sandbox updated. So whats the best way to do this?
There is a great post over at the “Left on the Web” blog, that walks you through how to distribute your Symfony application enbedded within your project by using svn:externals. Be sure to check it out.
5 Oct
So work is beginning in the symfonynerds camp on a few 1.1 apps (just in time to have to migrate to 1.2 :p) and I thought it was time to start documenting some of the little tips we have for it.
Today I was fine tuning an app for UAT and wanted to configure the ‘years’ being listed in a sfWidgetFormDate Date Select.
In the first instance, it was for a ‘date of birth’ field, so I was looking for a range from about 1900 to 2000. The first thing that came to mind was the php function range() but as per this ticket raised (which I commented on as well as posting here) doesn’t work because the array keys increment from 0… So if you selected 1900, your year would be submitted as 0.
One way around it is to create a variable of your own with keys and values for the years, then pass it as the ‘year’ option, like the below.
$years = range(1920, 2000); //Creates array of years between 1920-2000 $years_list = array_combine($years, $years); //Creates new array where key and value are both values from $years list new sfWidgetFormDate(array('years' => $years_list))
Perhaps in the future Symfony could offer a way of automating this with ‘year_min’ and ‘year_max’ options for sfWidgetDormDate, or readers have a faster way of doing it.
30 Jun
If you haven’t heard, Symfony 1.1 is finally out. We at SymfonyNerds.com were so excited, we gathered around one desk and went through the doco together, and then we held hands and sang kumbaya…. On a serious note some awesome features of 1.1:
You can read more about the official release notes here.
Let us know about your upgrade experiences, we will be upgrading some of our apps shortly - and will share our experiences with you.
26 Jun
Exporting to excel isn’t really something that’s symfony specific. There are plenty of good PHP libraries out there that can allow you to do some pretty advanced Microsoft Excel stuff with PHP.
In this example, I’ll show you how to get a view exporting to Excel. This is a very basic example that will get you started - with no external third-party libs.
Firstly, modify your actions class to turn off any layout template , do your sql query and then change the HTTP headers to have a response type of ‘application/msexcel’:
1 2 3 4 5 6 7 8 9 10 11 | public function executeList() { //Turn off the layout $this->setLayout(false); //My query $this->accounts = AccountPeer::doSelect(new Criteria()); //Export the output in Excel $this->getResponse()->setContentType('application/msexcel'); } |
Then in your view, all you need to do is have a basic HTML non-formatted table. For example, the contents of listSuccess.php could look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <table> <thead> <tr> <th>Account</th> <th>Type</th> ... </tr> </thead> <tbody> <?php foreach ($accounts as $account): ?> <tr> <td><?php echo $account->getCompanyName() ?></td> <td><?php echo $account->getAccountType() ?></td> ... </tr> <?php endforeach; ?> </tbody> </table> |
Thats it! Simple!
If you want to do some more advanced stuff - you should get a third-party lib, but if all your after is to export one view into a single Excel workbook with PHP and Symfony - this should be all you need.
20 Jun
This isn’t really Symfony related, but its PHP related. Its such a great feeling to know you have saved a potential 4 lines of code, by using a one-line if.
My original code:
if (sizeof($accounts==1)){ echo "There is one account attached to this company"; } else{ echo "There is ".sizeof($accounts)." accounts attached to this company"; }
That’s a massive 6 lines of code. People - think of the environment! In this day an age we can’t afford all these extra lines!
Switch it over to a one-line if. My one-liner:
//My sexy one-line if command echo "There ". ((sizeof($accounts)==1) ? " is one account attached to this company." : " are ".sizeof($accounts)." accounts attached to this company.");
Now how sexy is that! Of course, the code has become more illegible, and I’ve wasted one line commenting on how sexy it is, but heck - its cool.