如何在CakePHP中组织共享功能?

I need create a lot functions, used by 6+ Controllers. So... shared functions:

This functions needs:

  • Model Access
  • Database Access
  • Lib Access
  • Vendor Access
  • Plugin Access
  • View Redirect
  • Return parameters (callback)

What the best way?

  • Lib
  • Component
  • Behavior
  • Vendor

My website configuration:

  • CakePHP 2.3
  • MySQL 5.5
  • PHP 5.3.9
  • Apache 2.2

Sorry for my english. Thanks.

Helpers are for (multiple) views
Behaviors are for (multiple) models
Tasks are for (multiple) shells
Components are for (multiple) controllers

So - if you share those functions across controllers, the logical answer would be to use components.

All the rest of your "options" provided fail for at least one reason.

But keep in mind that you still have to keep the model stuff close to the model layer and should only use it via model methods in the controller/components. Don't make those components a powerful model or something. They are meant to share "logic" between controllers.

Simply you can write those function in Appcontroller file so you can access them globally.