0

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;

kzpm
  • 133
  • 11
  • Cake 2 and 3 have their own maintenance line and are not compatible that much. In fact, the ORM API has changed a lot. I think the answer to your question depends on what you want to do with that `Cake\ORM\Table`. "To populate $myvar with information." seems a little ambiguous to me; To perform table-level operations or raw queries, just reading some schema or w.e. Please clear out what your purpose exactly is, so people can exactly tell you the equivalent in cakephp-2.9. – Ali Asgari Nov 15 '18 at 05:11

2 Answers2

0

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

Antoine Thiry
  • 2,362
  • 4
  • 28
  • 42
JohannSan
  • 27
  • 6
0
ClassRegistry::init('YourModel')->find('first');
Chris Pierce
  • 706
  • 5
  • 9