0

I am very new in cakephp and i have to upgrade a cake project from version 1.1 to 3.6. I do not know how to convert these lines of code to cakephp 3.6:

    App::import('Model', 'SystemMenu');
    $system_menu =& new SystemMenu();

SystemMenu is an model which was define in Model folder.

Thank you very much for your help.

tiepvut
  • 90
  • 9
  • bin/cake bake model SystemMenus , bin/cake bake cell SystemMenus, load model in display method and make query, implement results in display.ctp template. use template.... – Salines Sep 17 '18 at 15:42

2 Answers2

1

If youre within a controller, you can do

$this->loadModel('SystemMenus');

and access the model like so

$this->SystemMenus->find()->...

If not, you can use TableRegistry

$systemMenus = TableRegistry::get('SystemMenus')

And access is simple:

$systemMenus->find()->...

See https://book.cakephp.org/3.0/en/orm/table-objects.html for more information

Notice that i have changed the table name to be plural, as the CakePHP 3.x conventions specifies https://book.cakephp.org/3.0/en/intro/conventions.html

Vindur
  • 364
  • 3
  • 12
0

You can use TableRegistry class.

$system_menu = \Cake\ORM\TableRegistry::get('SystemMenu');

//new entity
$entity = $system_menu->newEntity();

//get entity by id 
$entity = $system_menu->get(2);

//Save entity
$system_menu->save($e);

// finder 
$menu = $system_menu->find()->toArray();
Dariusz Majchrzak
  • 1,227
  • 2
  • 12
  • 22