如何使用不同的表名在Cake 3中的数据库中

时间:2017-05-05 07:14:50

标签: model cakephp-3.0

我正在使用cake php 3.4。 我在数据库中有来宾和国家表。 我想以Guest和Contries的形式访问这些表对象。

我想这样用:

$this->Guests->find(); 

而不是

$this->Guest->find()

1 个答案:

答案 0 :(得分:2)

您必须在 src / Model / Table /

中创建model GuestsTable.php
namespace App\Model\Table;

use Cake\ORM\Table;

class GuestsTable extends Table
{

    public function initialize(array $config)
    {
        $this->setTable('guest'); // your table name

        // Prior to 3.4.0
        // $this->table('guest');
    }

}

同样适用于国家