【问题标题】:Point cakephp 3 model to a different table将 cakephp 3 模型指向不同的表
【发布时间】:2015-07-03 14:45:39
【问题描述】:

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

在 Cakephp 2 中,我将使用 public $useTable = 'dev_pictures'; 将“图片”模型指向“dev_pictures”表,在 Cakephp 3 中,这没有效果。我将如何在 Cakephp 3 中做到这一点?

【问题讨论】:

    标签: cakephp model cakephp-3.0


    【解决方案1】:

    Why not simply reading the migration guide?

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

    【讨论】:

    • Table::table()$useTable 的弃用未在迁移指南(当前版本)中提及。
    【解决方案2】:

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

    class Picture extends AppModel {
    
        public $useTable = 'dev_pictures';
    
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多