0

I have a Symfony 1.4 and Doctrine 1.2 project running and have a problem with output escaping in one of my DB calls.

The thing is, I am not retrieving a PHP object in my Doctrine query, but rather an array in PHP. The reason why I am doing this is another topic altogether, let's just say getting a PHP object would not be the solution. Essentially the query is an inner join between two doctrine models. Model 1 inner joins with Model 2 and the results yielded can be accessed like this:

foreach($results as $result)
{
 echo $result['field1']; // accessing results for model 1 
 echo $result['model2']['field1']; // accessing results for model 2 (this inner joins with the model)
}

Now for the above, more specifically for model2, field1 consists of HTML markup, which is naturally output escaped. I need the HTML markup to be rendered as it is! Which is where the problem lies,

if this was a regulation Doctrine object, a simple $modelObject->getRawValue()->getField(); would render HTML markup without escaping it. I am not sure how HTML markup can be rendered in a PHP array?

Thanks

user1020069
  • 1,540
  • 7
  • 24
  • 41
  • 1
    I wonder, if you `print_r($result)` inside your loop, you might find it is wrapped in an escaper object. If so, you should be able to use `getRawValue()` on its elements as well? – halfer Apr 11 '12 at 20:21
  • Halfer, most of your solutions are comments, how do I accept those as answers ? – user1020069 Apr 11 '12 at 20:33
  • If you see a comment that works for you, just ask the poster to copy their comment into an answer, and accept! I do it all the time. If that helped, then great - been there, scratched my head for ages `:-)`. – halfer Apr 11 '12 at 20:50
  • Halfer post the comment as an answer, you got it! – user1020069 Apr 11 '12 at 20:54

1 Answers1

2

(Copied from my earlier comment). I wonder, if you print_r($result) inside your loop, you might find it is wrapped in an escaper object. If so, you should be able to use getRawValue() on its elements as well?

This works because the escaper object implements the Iterator interface (so you can do the foreach over it) and also ArrayAccess (so it appears to work like an array).

halfer
  • 19,824
  • 17
  • 99
  • 186