douluhaikao93943 2013-03-07 12:24
浏览 13
已采纳

如何在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.

  • 写回答

2条回答 默认 最新

  • doukou4066 2013-03-07 12:42
    关注
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面