0

I'm new in cakephp 3.5. I just recently read the same question and I use those solutions. The problem is I tried the solution answered in the past question but it didn't display the needed attributes.

view.ctp (client_transaction)

<div class="related">
    <?php if (!empty($clientTransaction->service_detail)): ?>
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th scope="col"><?= __('Service Detail ID') ?></th>
            <th scope="col"><?= __('Barber') ?></th>
            <th scope="col"><?= __('Service') ?></th>
            <th scope="col"><?= __('Price') ?></th>
            <th scope="col" class="actions"><?= __('Actions') ?></th>
        </tr>
        <!--pre>
        <?php print_r($clientTransaction->service_detail); ?>
      </pre-->

        <?php foreach ($clientTransaction->service_detail as $serviceDetail): ?>
        <tr>
            <td><?= $this->Number->format($serviceDetail->id) ?></td>
            <!-- the first solution-->
            <td><?= h($serviceDetail->users->first_name)?></td>
            <!-- the second solution-->
            <td><?= h($serviceDetail->service->name) ?></td>
            <td><?= h($serviceDetail->service->price) ?></td>
            <td class="actions">
                <?= $this->Form->postLink(__('Cancel'), ['controller' => 'ServiceDetail','action' => 'delete', $serviceDetail->id], ['confirm' => __('Are you sure you want to cancel # {0}?', $serviceDetail->id)]) ?>
        </tr>
        <?php endforeach; ?>
    </table>
    <?php endif; ?>
</div>

The screenshot of the error

I'm just asking for help. I'm also trying to figure it out. Thank you!

P.S: I just edited the code and the screenshot so that you'll get understand of the problem. thanks!

1 Answers1

0
<?php foreach ($clientTransaction->service_detail as $serviceDetail): ?>
    <tr>
        <td><?= $this->Number->format($serviceDetail->id) ?></td>
        <!-- the first solution-->
        <td><?= $serviceDetail->user!==null ? h($serviceDetail->user->first_name) : ''?></td>
        <!-- the second solution-->
        <td><?= h($serviceDetail['service']['name']) ?></td>
        <td><?= h($serviceDetail['service']['price']) ?></td>
        <td class="actions">
          <!--  <?= $this->Html->link(__('View'), ['controller' => 'Users', 'action' => 'view', $user->id]) ?>
            <?= $this->Html->link(__('Edit'), ['controller' => 'Users', 'action' => 'edit', $user->id]) ?> -->
            <?= $this->Form->postLink(__('Cancel'), ['action' => 'delete', $serviceDetail->id], ['confirm' => __('Are you sure you want to cancel # {0}?', $serviceDetail->id)]) ?>
    </tr>
    <?php endforeach; ?>

That should be - remember to remove your IF: (I hope this help)

<?php foreach ($clientTransactions as $serviceDetails): ?>
    <?php foreach ($serviceDetails->service_detail as $serviceDetail): ?>
           //Code to excute here
    <?php endforeach; ?>
<?php endforeach; ?>

not:

<?php foreach ($clientTransaction->service_detail as $serviceDetail): ?>
Mr.D
  • 89
  • 1
  • 11
  • It doesn't work. That is already given by bake cakephp. The barber, service name and price shows their primary key. I want to show the name of the users, service name and price instead of id – Maria Theresa Chavez Mar 12 '18 at 11:58