cakephp 3.0 使用 tableprefix 吗?

标签 cakephp cakephp-3.0

从 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/

相关文章:

Cakephp 3.5.6 禁用 Controller 的 CSRF 中间件

php - 全局更改 CakePHP 数据库配置

mysql - cakephp 博客文章中缺少图像

php - cakephp 出错

php - 使用 cake3 php 获取搜索表单结果的 get 请求获取关联数据

javascript - CakePhp3 - 在 ChartJs 上显示值

php - CakePHP 3.X 中的自动完成小部件

validation - 如何更改 buildRules [CakePHP 3] 中的消息?

php - CakePHP:使用 optgroups 在选择上设置默认值

Cakephp 主页逻辑