Friday, July 9, 2010

Cake 1.2 / 1.3: how to Instantiate helper with options?

Hi there everyone,

I would like to know if it's possible to instantiate a helper in a
controller with configuration options (like one can with components,
or with model behaviors).

What I'd like to do is pre-set certain options for the Form helper
(div => false) for example, instead of having to do it each and every
time I add a form field in the view. I've done a bit of a search in
the Book, and also on the web, but I've not found anything that lead
me to an answer.

What I thought, as an alternative, is to write a wrapper helper class
(e.g. MyForm) that uses the Form helper with wrapper functions around
each of the Form helper's functions; this approach should work but it
seems like a long way around solving the problem. I'd like to avoid
this if possible.

I am in the process of refactoring a site I did about 2 years ago in
Cake 1.1; I've upgraded to 1.2.7 and plan to upgrade even further to
1.3.2 before deploying the updated version of the site. I'm also using
this as an exercise in improving my own Cake skills, trying to keep
the code as "cake-like" as possible.

Any pointers in this regard would be much appreciated.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: