LoginSignup
22
15

More than 5 years have passed since last update.

CakePHP3.6でいつの間にか TableRegistry::get()が非推奨になっていた

Posted at

概要

タイトルのまんまです。

3.5 までは日常的に使用されていた
TableRegistry::get()deprecated になっていました。

代替えコード

3.6移行ガイド

移行ガイドによると
Cake\ORM\TableRegistry の static な API は非推奨となったらしいです。

代わりに Cake\ORM\TableRegistry::getTableLocator()Cake\ORM\Locator\LocatorAwareTrait を介して使用するんだよと。

ただ、Controllerにて使用する場合には、Controller の基底クラスにて上記 Trait が use されているので、実際には

SampleController.php

$table = $this->getTableLocator()->get('ModelName');
$entity = $table->newEntity();

といった風に使用できるようです。

22
15
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
22
15