How to use table name different then in database in cake php 3

你说的曾经没有我的故事 提交于 2019-12-13 07:32:00

问题


I am using cake php 3.4. I have guest and country table in database. I want to access these table object as Guests and Contries.

I want to use like this :

$this->Guests->find(); 

instead of

$this->Guest->find()

回答1:


You have to create a model GuestsTable.php in src/Model/Table/

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');
    }

}

Same goes for country



来源:https://stackoverflow.com/questions/43798764/how-to-use-table-name-different-then-in-database-in-cake-php-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!