More gotchas from the Symfony world
Well, it seems there’s a few other things that aren’t as they seem in Symfony - if they’re expected or not, they are things I’ve noticed and needed a few minutes (or in a another case) or just over two hours to figure out.
All of them have to do with Symfony’s output escaper using PHPView. The first one is concerned with custom ResultSet objects that you pass into the template using a simple $this->anything assignation within an action or a component. Say you’re got a simple SQL query within a component or action that you want returned as a ResultSet (using Creole):
$SQL = "
SELECT *
FROM app_user
WHERE insertion_time > DATE_DIFF(CURDATE, INTERVAL ? DAY)
";
$stmt = Propel::getConnection()->prepareStatement($SQL);
$this->results = $stmt->executeQuery(
array(7), ResultSet::FETCH_ASSOC
);
You’d expect to have $results contain a ResultSet object that you can iterate over using a while($results->next()) {}, but you’re in for a surprise - it doesn’t work.
If you look closely at the variable within the template printed out using print_r(), you can see that the object is wrapped within an sfOutputEscaper (or variant of) object that intercepts certain functions. This is what seems to happen when using a ResultSet object - the wrapper escaper object overloads the methods and prevents ResultSet’s methods from being invoked.
The solution? Place $results = $results->getRawValue() somewhere before the while loop and everything works fine.
I’ll probably enter a ticket for this one, after I grab something to eat.




September 6th, 2007 at 6:51 pm
Hi. Could I translate some of your post and put them on my blog? Of course I`ll include link to source.
September 6th, 2007 at 8:34 pm
Sure, as long as you give credit where credit is due.
Note to self: might as well start thinking of putting up a license banner, something in the lines of CC.