Recently I have been working on my latest Cakephp app, and found Cakephp’s plugin architecture to be a great timesaver and helper. Totally I have 12 models, but only 3 in the regular app/model directory. The rest is located under the plugins:
- Authake (3 models) – handles users, user groups and roles
- Newsletter (5 models) – subscribers, groups, mails and reporting
- Comments (1 model) Build myself, and is plugable in any view since it is using the url as an relation
Both Authake and Newsletter needed some finishing and debugging, but if I was do build the same functionality myself I would have spent much more time.
Guidelines for building plugins
While taming these external plugins, you got a feel for what’s best praxis building plugins. As a short list I will emphasize these points:
- Use conventions! Admin functions should utilize the build in admin routes!
- Use conventions! Do NOT mock up to much with the baked views. Rather but your effort in writing smart, and good code in models, controllers, helpers and components. Avoid using icons instead of the edit, view and delete buttons/links!
- Comment code!
- Escape the messages with the __(“string”) function to make language translation or customization easier!
- When deploying a plugin I tent to move some views into the main view-folder in the app directory. At least I did that with the Newsletter-plugin (see above)
- Even though you are using SVN for your app, you can add a svn propedit svn:ignore plugins and check out other repositories in that directory