CakePHP将应用程序模型替换为插件中的模型
我想用这种方式扩展CakePHP(最新)应用程序中的模型和实体。我想告诉蛋糕使用ExtraStuff模型类而不是appStuffCakePHP将应用程序模型替换为插件中的模型,php,cakephp,Php,Cakephp,我想用这种方式扩展CakePHP(最新)应用程序中的模型和实体。我想告诉蛋糕使用ExtraStuff模型类而不是appStuff App\Model\Table\Stuff MyPlugin\Model\Table\ExtraStuff 我正在尝试使用Cake\Datasource\modelawaretrit /** * Override a existing callable to generate repositories of a given type. * * @param
App\Model\Table\Stuff
MyPlugin\Model\Table\ExtraStuff
我正在尝试使用Cake\Datasource\modelawaretrit
/**
* 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类。
谢谢。看看这个
如果您使用的是内置ORM以外的表提供程序,则可以通过连接其工厂方法将该表系统链接到CakePHP的控制器:
// In a controller method.
$this->modelFactory(
'ElasticIndex',
['ElasticIndexes', 'factory']
);
注册表工厂后,可以使用loadModel加载实例:
// In a controller method.
$this->loadModel('Locations', 'ElasticIndex');