# How to display data in a view cakephp3

**URL:** <https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500>\
**Category:** Uncategorized\
**Created:** [June 9, 2016, 5:33am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500 "2016-06-09T05:33:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 9, 2016, 5:33am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/1 "2016-06-09T05:33:40Z")

</div>

I have loaded a query in a pagination and how do i display the data in a view in cakephp3?  
In cakephp2 this was dead easy. In the docs I cant find how to display data from associated tables ?  
None of this works but the data exists

```
        <?php foreach ($lessons as $bookmark): ?>
        <tr>
            <?php 
           // debug( $bookmark);
            ?>
            <td><?php echo $bookmark['Lesson']['id'] ?></td>
            <td><?= h($bookmark->Lessons->id) ?></td>
            <td><?= h($bookmark->lesson_date) ?></td>
            <td><?= h($bookmark->Tutor.first_name) ?></td>
             <td><?= h($bookmark->Tutor.last_name) ?></td>
              <td><?= h($bookmark->Subject.name) ?></td>
          
        </tr>
        <?php endforeach; ?>
```

---

<div class="post-metadata">

**Author:** ![mehdifathi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mehdifathi/32/241_2.png) [@mehdifathi](https://discourse.cakephp.org/u/mehdifathi)\
**Post date:** [June 9, 2016, 5:36am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/2 "2016-06-09T05:36:29Z")

</div>

Hi your code is wrong you must code exaclly like `$bookmark->Tutor->first_name`.

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 9, 2016, 5:42am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/3 "2016-06-09T05:42:24Z")

</div>

Still isnt working and i debugged the data on the view below.  
This was so easy in cakephp2

Notice (8): Trying to get property of non-object

 \<?= h($bookmark-\>Lessons-\>id) ?\>

```
    <?= h($bookmark->Lesson->lesson_date) ?>
        <?= h($bookmark->Tutor->first_name) ?>
        <?= h($bookmark->Tutor->last_name) ?>
        <?= h($bookmark->Subject->name) ?>

```

object(App\Model\Entity\Lesson) {

```
'tutoring_type_id' => (int) 1,
'students' => [
	'id' => '75',
	'first_name' => 'Jes',
	'last_name' => 'ett'
],

'lessons' => [
	'id' => '5399',
	'lesson_date' => '2015-07-09'
],
'tutors' => [
	'id' => '12',
	'first_name' => 'Andrew',
	'last_name' => 'Toy'
],
'subjects' => [
	'id' => '16',
	'name' => 'Maths: Year 7 - 10'
],
```

---

<div class="post-metadata">

**Author:** ![mehdifathi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mehdifathi/32/241_2.png) [@mehdifathi](https://discourse.cakephp.org/u/mehdifathi)\
**Post date:** [June 9, 2016, 5:46am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/4 "2016-06-09T05:46:20Z")

</div>

> [@jagguy](#):
>
> tutors

> [@jagguy](#):
>
> \<?= h($bookmark-\>Tutor-\>first\_name) ?\>

you are mistaking.you must convert above code to tutors.just this

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 9, 2016, 5:48am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/5 "2016-06-09T05:48:40Z")

</div>

\<?= h($bookmark-\>tutors-\>first\_name) ?\> didnt work

where is this in the docs as I only see a basic example only?

---

<div class="post-metadata">

**Author:** ![mehdifathi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mehdifathi/32/241_2.png) [@mehdifathi](https://discourse.cakephp.org/u/mehdifathi)\
**Post date:** [June 9, 2016, 5:53am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/6 "2016-06-09T05:53:27Z")

</div>

yes there are a lot of example.I don’t why you have problem that is very simple.

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 9, 2016, 5:56am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/7 "2016-06-09T05:56:00Z")

</div>

SO what do i do as i got rid of the pagination to make it simpler  
//controller

```
    $this->set(compact('query3'));
    $this->set('_serialize', ['query3']);

```

//view

\<?php foreach ($query3 as $bookmark): ?\>

```
        <tr>
            <?php 
         // debug( $bookmark);
            ?>
          
            <td><?= h($bookmark->lessons->id) ?></td>
            <td><?= h($bookmark->lessons->lesson_date) ?></td>
            <td><?= h($bookmark->tutors->first_name) ?></td>
             <td><?= h($bookmark->tutors->last_name) ?></td>
            
          
        </tr>
        <?php endforeach; ?>
```

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 9, 2016, 11:47am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/8 "2016-06-09T11:47:49Z")

</div>

I can solve the problem but I dont get why I need to have model names in the select with lower case names and I dont get why these are not objects

```
           <td><?= $bookmark->lessons['id'] ?></td>
            <td><?= $bookmark->lessons['lesson_date'] ?></td>
            <td><?= $bookmark->tutors['first_name'] ?></td>
             <td><?= $bookmark->tutors['last_name'] ?></td>
             <td><?= $bookmark->subjects['name'] ?></td>
               <td><?= $bookmark->TutoringTypes['value'] ?></td>
```

---

<div class="post-metadata">

**Author:** ![neha02](https://avatars.discourse-cdn.com/v4/letter/n/8edcca/32.png) [@neha02](https://discourse.cakephp.org/u/neha02)\
**Post date:** [October 17, 2019, 6:25am UTC](https://discourse.cakephp.org/t/how-to-display-data-in-a-view-cakephp3/500/9 "2019-10-17T06:25:30Z")

</div>

> [@jagguy](#):
>
> subject

well i guess, your Lesson variable includes these arrays and the names of these arrays are all in lower case. and you are trying to fetch data from those arrays so you have to give exact same name as it is given in that lesson array’s data… try analyzing your debug code once more you’ll then get to knw what m talking about. 🙂
