Element or helper?
In a recent post Felix Geissendörfer presented the “MacGyver Menu”. He put the menu logic directly in the view and wrote:
If your menu logic is more complex [...] I suggest you to create either an element or an helper for it.
This statement sounds to me as if it doesn’t matter whether you create an element or a helper.
That’s not true. At least not for me. But fortunately, it is usually obvious whether something should be realized as an element or a helper.
As an element is a mini-view, it should contain only basic presentation logic like ifs, loops over data arrays, and calls to helpers. So we can say elements are primarily for reusing presentation “elements”. On the other hand we have the helpers which are used to reuse presentation logic.
With this distinction between presentation “elements” and logic it should be rather easy to decide whether you should create an element or a helper.
Happy baking :)




I only use helpers for the really ugly stuff like accessing models (which btw. is something the cake 1.2 form helper does as well) or registering complex JS stuff internally.
For a simple transformation of a couple variables into plain old html I’m very much in favor of elements, which btw. also has the advantage of giving you explicit caching support - something helpers won’t do out of the box.
@Felix: It seems we have different philosophies in this point ;-) I prefer to create helpers over elements, as helpers are easier to test (at least with my test suite).