Cakephp 2.9 alternative for cakephp 3.0 TableRegistry

142 Views Asked by At

In Cakephp 3.x I can use:

$myvar = TableRegistry::getTableLocator()->get('tablename')

To populate $myvar with information.

But what is the equivalent for the code above in CakePhp 2.9? And which class do I have to add? In CakePhp 3.x it seems to be use Cake\ORM\TableRegistry;

2

There are 2 best solutions below

0
JohannSan On

I'm assuming you want to get your table in a controller.

In that case, you can load a model like this:

$this->loadModel('YourModel');

In your controller

$this->YourModel

More here

0
Chris Pierce On
ClassRegistry::init('YourModel')->find('first');