【发布时间】:2018-04-16 19:41:17
【问题描述】:
我想以这种方式扩展我的 CakePHP(latest) 应用程序中的模型和实体。我想告诉蛋糕使用 ExtraStuff 模型类而不是应用程序 Stuff
App\Model\Table\Stuff
MyPlugin\Model\Table\ExtraStuff
我正在尝试使用 Cake\Datasource\ModelAwareTrait
中的方法在 beforeRender 方法中重新定义主控制器中的模型/**
* Override a existing callable to generate repositories of a given type.
*
* @param string $type The name of the repository type the factory function is for.
* @param callable $factory The factory function used to create instances.
* @return void
*/
modelFactory($type, callable $factory)
或者我该怎么做?我在项目中有很多 $this->loadModel('Stuff') 调用,我需要告诉应用程序在需要时使用 ExtraStuff 类。 谢谢。
【问题讨论】: