0

I am trying to fetch all records from users table as below code:

$this->loadModel('User');
$users_list = $this->User->find('all');
pr($users_list);

but the resulting page shows like below:

Cake\ORM\Query Object
(
  [_hasFields:protected] => 
  [_autoFields:protected] => 
  [_hydrate:protected] => 1

... continued with lot of lines

is I am writing anything wrong?... Thanks in advance

  • Will you elaborate this questions little more..How is the relations look like ? What is the name of the table and structure of table ? – Manohar Khadka Feb 23 '17 at 15:47

1 Answers1

1

For CakePhp3 that should be:

$this->loadModel('Users');
$users_list = $this->Users->find('all');

You can also use TableRegistry:

use Cake\ORM\TableRegistry;
$usersTable= TableRegistry::get('Users');
$users_list = $usersTable->find('all');

See Here:

1.Loading Model in CakePhp3

2.Using TableRegistry

What you have done is used for CakePhp2.

Manohar Khadka
  • 2,186
  • 2
  • 18
  • 30
  • I am used your code: written below loaded before class use Cake\ORM\TableRegistry; written below code in controller function: $usersTable= TableRegistry::get('Users'); $users_list = $usersTable->find('all'); but no change...getting same result – veerendra reddy Feb 23 '17 at 15:08
  • Given that the output shows that `$users_list` is a query object, it looks like the OP is actually operating with a proper table object. Not following the naming conventions does work, even if it's not recommended (could have also been just a typo in the example maybe). The actual problem seems to be that the OP doesn't know about the new ORM basics with regards to query objects, lazy evaluation, etc. – ndm Feb 23 '17 at 15:08