从 cakephp 2 应用程序开始,我一直在尝试在模型中使用 $tablePrefix。 Cake 3 中还可以使用此功能吗?或者我怎样才能使用其他东西(请解释)。
最佳答案
表前缀暂时消失了。有一个公开的 PR,但目前还不清楚何时以及是否会成功:
<强> https://github.com/cakephp/cakephp/pull/4505
正如 Lorenzo 在评论中提到的,另一种方法可能是使用事件来初始化具有前缀表名的模型:
For people still wanting support for prefixes in their tables, there is a way to support it using events. This will probably work for all table operations. Add it to your bootstrap.php file:
EventManager::instance()->on('Model.initialize', function ($event, $instance) { $instance->table('prefix_' . $instance->table()); });
<强> https://github.com/cakephp/cakephp/pull/4505#issuecomment-76154855
关于cakephp 3.0 使用 tableprefix 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28792720/