开发者

White labeling CakePHP: What's the best way to provide customization hooks/callbacks to implementers?

开发者 https://www.devze.com 2023-01-18 23:15 出处:网络
I\'m developing a CakePHP application that we will provide as a white label for people to implement for their own companies, and they\'ll need to have certain customization capabilities for themselves

I'm developing a CakePHP application that we will provide as a white label for people to implement for their own companies, and they'll need to have certain customization capabilities for themselves.

For starters, they'll be able to do anything they want with the views, and they can add their own Controllers/Models if they need to add completely new stuff. However, I'd rather advise against touching my controllers and models, to make version upgrading easier.

Esentially, the customization capabilities I'm planning to give them are going to be quite basic, I just need to call "something" when certain things happen, so they can do things like update external systems, e-mail themselves/the clients, things like that.

I'm wondering what's the best way to do this?

My plan is to have a "file" (with one class) for each controller of mine, to keep things reasonably organized. This file will have a bunch of empty methods that my code will call, and they'll be able to add code inside those methods to do whatever they need to do.

The specific question is, should this class full of empty methods be a Component? A Controller? Just a regular plain PHP class?

I'll need to call methods in this class from my Co开发者_StackOverflowntrollers, so I'm guessing making it a Controller is out of the question (unless maybe it's a controller that inherits from mine? or mine inherits from theirs, probably). Also, I'd need the implementer of these methods to have access to my Models and Components, although I'm ok with making them use App::Import, I don't need to have the magic $this->ModelName members set.

Also, does this file I create (etiher Component or Controller) have to live in the app folder next to the other (my) controllers/components? Or can I throw it somewhere separate like the vendors folder?

Have you done something like this before?

Any tips/advice/pitfalls to avoid will be more than welcome.

I know this is kind of subjective, I'm looking to hear from your experience mostly, if you've done this before.

Thanks!


Two ideas that spring to mind:

  • create abstract templates (controllers, models, whatever necessary) that your clients can extend
  • write your controllers/components/models as a plugin within their own namespace

Ultimately you seem to want to provide an "enhanced" Cake framework, that your clients still have to write their own Cake code in (I don't know how this goes together with your idea of "basic customization capabilities" though). As such, you should write your code in as much an "optional" manner as possible (namespaced plugins, components, AppModel enhancements, extra libs) and provide documentation on how to use these to help your clients speed up their work.


I would setup a common set of events and use something like the linked to event system to handle this.

That lets the clients manage the event handler classes (read the readme to see what I mean) and subscribe to and broadcast events application-wide.

Also - if you want to have your users not muck about with your core functionality I recommend you package your main app as a plugin.

http://github.com/m3nt0r/eventful-cakephp

0

精彩评论

暂无评论...
验证码 换一张
取 消