devendra singh
devendra singh

Reputation: 219

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

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()

Upvotes: 1

Views: 1156

Answers (1)

Aman Rawat
Aman Rawat

Reputation: 2625

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

Upvotes: 3

Related Questions