Q: How to use cakephp loadmodel inside the default pages controller? I have been trying to load a model inside the CakePHP default pages controller but to no avail. How do I use the CakePHP loadmodel inside the pages controller? Below is my code:
public function display() {
$this->loadModel('User');
    $user = $this->User->find('all');
    $this->set('users',$user);
}

Here is my view, that is, the default home.ctp:
<?php foreach ($users as $user):
 echo $this->Html->link($user['User']['username'], array('action' =>     'view', $user['User']['id']));
?>
<?php endforeach; ?>


A: It seems like you are reading the wrong version doc.
If your CakePHP version is 2.x, you don't "load" it, you say that the Controller uses the models like this:
<?php
 class MyController extends AppController{
   public $uses = ['ModelName'];//Setting needed tables/models

   public function myAction(){
     //Now you can keep going normally
     $this->set('results', $this->ModelName->find('all'));
   }
 }

But if your CakePHP is 3.x. It seems to have the right call, but be sure that you have created the correspondent file under "src/Model/Table/UserTable.php". 
And the select method has changed, see:
<?php
 // in src/Controller/PagesController.php
 namespace App\Controller;

 use App\Controller;

 class PagesController extends AppController{
   public function initialize(){
     parent::initialize();
     $this->loadModel('User');
   }
   public function display(){
     $users = $this->User->find()->toArray();
     $this->set('users', $users);
   }
 }

See the doc for CakePHP 3.x over here
