1
votes

I've written a helper to help with generating URLs in my CakePHP 2.3 app. Basically it's a wrapper around Cake's built-in functionality, that helps handle routing prefixes, avoids key/value array pairs for common things, etc, to make the code a bit tidier.

The problem is, I need basically all the same functionality for easily generating these URLs from my helper, available in my controllers - for things like loginRedirect, redirecting after edits, etc.

Is there a good solution for sharing logic between Controllers and Views without duplicating code? I understand that in general Views and Controllers shouldn't share code - but there are exceptions.

1

1 Answers

0
votes

You can create a 'Utility' and create 'Helper' and 'Component' wrappers for that, that can be used inside your Controller and Views, something like the TextHelper / String Utility combination.