views:

361

answers:

1

Is it possible to set a template variable in a helper?

Ultimately what I'm trying to do is have a helper add in code to the header of the layout, for use with javascript and such.

Ways I can think of that I'd prefer not to use:

  • Passing in the view object: don't want to worry about having to call an extra function
  • using the "global" keyword to get the view, I really like to avoid using this except as a last resort since it's not considered orthodox

Any thoughts?

+1  A: 

I discovered you can use the class registry to grab it, so I made this function in my helper:

/**
 * Access to the view for special operatoins
 */
protected function getView() {
    return ClassRegistry::getObject('view');
}
SeanDowney