Move php from view to code