# CakePhP 3: Using $this-\>loadModel for an unrelated Model in Controller

**URL:** https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285
**Category:** Need Help
**Created:** [May 10, 2016, 8:32am UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285 "2016-05-10T08:32:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![andystorey](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/andystorey/32/186_2.png) [@andystorey](https://discourse.cakephp.org/u/andystorey)
#### Post date: [May 10, 2016, 8:32am UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/1 "2016-05-10T08:32:35Z")

</div>

Dear CakePhP Forum Members

I have been using CakePhP for 2 months now and have to say it’s been a revelation! It’s a **_great_** framework.

**_My problem is:_** I currently have a need to load a model in a controller for a completely unrelated (SQL wise) model. Here is my basic ‘Races’ index controller method:

```
public function index()
{
    $this->loadModel('Pages');
    
    $this->set('races', $this->Races->find('all', ['contain' => ['Countries'], 'order' => ['races.name' => 'ASC']]));

    $page = $this->Pages->find('all', ['conditions' => ['Pages.current_url LIKE' => '/races/']]);
    $this->set('page', $page->first());

    $this->set(compact('races','page'));
    $this->set('_serialize', ['races','page']);

}

```

I am then trying to have the following in the ‘Races’ index.ctp

\<?= h($page-\>body) ?\>

Which brings up an error - what am I doing wrong?

All/any help most grateful received!

andy

---

<div class="post-metadata">

### Author: ![lorenzo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/lorenzo/32/25_2.png) [@lorenzo](https://discourse.cakephp.org/u/lorenzo)
#### Post date: [May 10, 2016, 10:51am UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/2 "2016-05-10T10:51:53Z")

</div>

What is the error you are getting?

---

<div class="post-metadata">

### Author: ![andystorey](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/andystorey/32/186_2.png) [@andystorey](https://discourse.cakephp.org/u/andystorey)
#### Post date: [May 10, 2016, 11:28am UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/3 "2016-05-10T11:28:43Z")

</div>

Sorry - should have put that up!

Notice (8): Undefined property: Cake\ORM\Query::$body [APP/Template\Races\index.ctp, line 13]  
Code Context  
include - APP/Template\Races\index.ctp, line 13  
Cake\View\View::\_evaluate() - CORE\src\View\View.php, line 992  
Cake\View\View::\_render() - CORE\src\View\View.php, line 952  
Cake\View\View::render() - CORE\src\View\View.php, line 587  
Cake\Controller\Controller::render() - CORE\src\Controller\Controller.php, line 611  
Cake\Routing\Dispatcher::\_invoke() - CORE\src\Routing\Dispatcher.php, line 120  
Cake\Routing\Dispatcher::dispatch() - CORE\src\Routing\Dispatcher.php, line 87  
[main] - ROOT\webroot\index.php, line 36

---

<div class="post-metadata">

### Author: ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)
#### Post date: [May 10, 2016, 12:02pm UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/4 "2016-05-10T12:02:55Z")

</div>

The error message itself showing you the solution. There is no body property for $page. If you are expecting body property try to debug $page.

---

<div class="post-metadata">

### Author: ![lorenzo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/lorenzo/32/25_2.png) [@lorenzo](https://discourse.cakephp.org/u/lorenzo)
#### Post date: [May 10, 2016, 12:14pm UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/5 "2016-05-10T12:14:21Z")

</div>

> [@andystorey](#):
>
> $page = $this-\>Pages-\>find(‘all’, [‘conditions’ =\> [‘Pages.current\_url LIKE’ =\> ‘/races/’]])

You are using `'all'` instead of `->first()` at the end… Do you want all pages or just one?

---

<div class="post-metadata">

### Author: ![andystorey](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/andystorey/32/186_2.png) [@andystorey](https://discourse.cakephp.org/u/andystorey)
#### Post date: [May 10, 2016, 7:45pm UTC](https://discourse.cakephp.org/t/cakephp-3-using-this-loadmodel-for-an-unrelated-model-in-controller/285/6 "2016-05-10T19:45:51Z")

</div>

THANKS Lorenzo! 🙂
