LoginSignup
11
9

More than 5 years have passed since last update.

CakePHP 3で命名規則に沿わないTableクラスを作る

Posted at

CakePHP入門のため、苦労しているまっただ中。
CakePHP 2系の情報はよく出てくるものの、CakePHP 3系の情報に行き当たるまでに結構苦労したので…。

やりたいこと

Tableクラスのクラス名はWeathersTableにしたい。
このクラスをtbl_weatherというテーブル名に関連付けたい。

CakePHP 2系での書き方。

以下のように書く…らしいのだが、おいらはCakePHP 2を使ったことがないので、あっているか分からん。

class Weathers extends AppModel {
    public $useTable = 'tbl_weather';
}

CakePHP 3系での書き方

class WeathersTable extends Table
{
    public function initialize(array $config)
    {
        $this->table('tbl_weather');
    }
}

で、公式のCookbookにちゃんと載っていましたとさ。

11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9