The whole code in the controller is ... er, not optimal. It belongs to a Model and definitely to a basic shared one.
I'm not sure I want to change that much.

As I said, this enhances the previous solution created by Josef. I believe he also wanted to easiest solution ;)

Anyway, storing the info in a variable seems to be a good idea. I will do that.