Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.


Stack Overflow

The old fashioned way


  Uncategorized Articles

July 21, 2009 – 5:06pm Propel criteria on custom columns (with addAsColumn)

This still trips me up. If you are using propel criteria objects and want to add a condition on a custom column, you have to do a bit of trickery to get it working just right. More…

Posted by in  Uncategorized   |     |  4 Comments »

July 13, 2009 – 10:37am Symfony: returning an array from app.yml

Sometimes its useful to return an array of values from app.yml. This is buried in the symfony docs so I thought I’d post it here just in case it’d help.

I’ve been using this technique to store a list of languages available on a site. As translations are ready for other languages, I add them to the list here and they automatically get pulled into the code in the appropriate places:

Posted by in  Uncategorized   |     |  7 Comments »

July 11, 2009 – 2:52am php isset and not empty

I find myself doing this a lot:

if (isset($myarray['foo']) && $myarray['foo'])) {
  // do something

But I thought there had to be a better way, and one that would not throw undefined errors. A quick google search came up with a few good hits, include the PHP manual page for empty().

The manual says that when using empty(), no warnings are thrown when a variable is not set. It will return true in the following cases:

“” (an empty string)
0 (0 as an integer)
“0” (0 as a string)
array() (an empty array)
var $var; (a variable declared, but without a value in a class)

Keep in mind that an object with no properties is not considered empty().

Now, we can make our code a bit more beautiful:

if (!empty($myarray['foo'])) {
  // do something

I’ve known about empty() for a long time, but for some reason always seemed to choose isset() over empty(), even in cases like this.

Posted by in  Uncategorized   |     |  3 Comments »

July 1, 2009 – 6:30pm Firebug and Firefox 3.5

I rely on Firebug daily to help me debug javascript and work with css. After upgrading to Firefox 3.5, I updated Firebug to the latest beta release, Firebug 1.4 Beta.

The beta version is of course rough around the edges, and one rough spot is the fact that often when editing css properties of an element on an html page, the entire style definition would simply disappear from the console.

Fortunately, as of today, the firebug-1.5X.0a07.xpi release fixes the problem. Click the link for 1.5X0a07.xpi within Firefox to update. I haven’t found any serious problems with the alpha version yet.

As a side note, if any of you are Safari users or are just testing your sites out for safari, make sure you enable the development menu (Preferences > Advanced > Enable Develop Menu) and then you can use the command-option-i to show a Firebug-like inspector. It’s growing on me each time I use it.

Posted by in  Uncategorized   |     |  2 Comments »

March 14, 2009 – 2:46pm Symfony Propel Enum types

Propel does not support enum column types in its schemas, since the enum type is not support across all database types. There are a few ways around this. More…

Posted by in  Uncategorized   |     |  4 Comments »

March 11, 2009 – 1:55am Symfony: How to render a partial from an action

If you ever find yourself wanting to return the contents of a partial as the entire response for an action, Symfony makes it possible. Using symfony partials with ajax, you have a lot of options of how you want to arrange your templates, but here I’ll show you what has worked best for me.

Oftentimes I find myself wanting to return the contents of a partial as the entire response for an ajax request. I do this a lot when I am already using a partial in my template, and then I want to replace that section with the results of an ajax call. We already have a partial set up to display that content, so we might as well reuse it when we have to refresh that area with new content. More…

Posted by in  Uncategorized   |     |  7 Comments »

March 5, 2009 – 5:44pm Create zip archive from the command line

I never remember how to do this. I like doing it from the terminal better than the “Compress X Items” option in the finder, because the finder method will sometimes add hidden files like __MACOSX which I don’t like seeing floating around.

This is so simple, it’s stupid. More…

Posted by in  Uncategorized   |     |  Comments Off on Create zip archive from the command line

December 23, 2008 – 9:09pm Symfony 1.2: upload a file inside an embedded form

Symfony 1.1 introduced the ability to embed forms inside other forms. Symfony 1.2 enhanced this feature greatly by providing the ability to automatically save any related objects found within these nested forms (see this blog post). Another new feature introduced in 1.2. is the ability to automatically handle file uploads in forms. Basically if you have a propel object with a file field, and define this field in your form validation schema as an sfValidatorFile, symfony takes care of removing any old field, saving the new one, and updating the column in the object to reflect the new file name. Pretty sweet. (You can read more about this feature in What’s New in 1.2.)

Everything is nearly perfect, except one problem: File fields in embedded forms are *not* processed automatically. It took me a long time to track down the issue, but it was a good opportunity for me to explore some of the new sfForm framework and really get under the hood to understand how it all works. More…

Posted by in  Uncategorized   |     |  28 Comments »

November 21, 2008 – 5:39pm Javascript get window hash/anchor, get link target

There are two functions I find myself using all the time. They are very useful for javascript events that read the link href attribute to determine an action’s target. More…

Posted by in  Uncategorized   |     |  7 Comments »

November 21, 2008 – 1:08pm Installing Xdebug for PHP on OS X Leopard with Entropy PHP 5

I was so ready to get my hands dirty with this. Like most cases where I try to install a custom extension or php library, the directions may appear easy but it never quite goes so smoothly. More…

Posted by in  Uncategorized   |     |  Comments Off on Installing Xdebug for PHP on OS X Leopard with Entropy PHP 5