将 cakephp 3 模型指向不同的 table

Point cakephp 3 model to a different table

出于数据库组织的目的,我为每个 table 添加了借口。 然后我会在 Cakephp 中不带任何借口地命名模型,以便在调用它们时减少编写。

在 Cakephp 2 中,我会使用 public $useTable = 'dev_pictures'; 将 "Picture" 模型指向 "dev_pictures" table,在 Cakephp 3 中,这没有任何效果。我将如何在 Cakephp 3 中做到这一点?

Why not simply reading the migration guide?

现在是Table::table(),方法是getter和setter。在 tables initialize() 方法中设置 table 名称。

CakePHP 3.0 不支持 table_prefix 并且 3.1 似乎没有解决这个问题。因此,与此同时,我认为最简单的解决方案是执行以下操作:

class Picture extends AppModel {

    public $useTable = 'dev_pictures';

}

(考虑到 CakePHP 2.x 前缀支持不是很可靠)。