Element or helper?

Published on and tagged with cakephp  element  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 :)

3 comments baked

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License