Why does view.ctp change not make affect the view?

I’m new to cakephp. I don’t want to display a column, but, removing it, from view.ctp doesn’t seem to take any affect? Why is that? Also, I have two tables X and Y. But view.ctp for X is showing the Y columns? and the Y view.ctp is showing the X columns? What gives?

Are you sure you’re changing the right file?

Typically, view.ctp shows a single instance of a record, and index.ctp shows a list of records.

If X and Y have a relationship, then the view.ctp for X might list the related Y records.

To prevent confusion, it’s probably better to give code of the view.ctp you are changing, and the actual output as HTML or a screenshot.

Hi,

Thanks for the reply. X and Y have many-to-many relationship.
I ran “cake bake all X” and "cake bake all Y"
X is staff
Y is client.

under src->template->staffs->view.ctp
when I change this file ( delete some of the columns from the table because I don’t want to display all of them), save, refresh the page, not seeing any changes

  • <?= __('Actions') ?>
  • <?= $this->Html->link(__('Edit Staff'), ['action' => 'edit', $staff->id]) ?>
  • <?= $this->Form->postLink(__('Delete Staff'), ['action' => 'delete', $staff->id], ['confirm' => __('Are you sure you want to delete # {0}?', $staff->id)]) ?>
  • <?= $this->Html->link(__('List Staffs'), ['action' => 'index']) ?>
  • <?= $this->Html->link(__('New Staff'), ['action' => 'add']) ?>
  • <?= $this->Html->link(__('List Locations'), ['controller' => 'Locations', 'action' => 'index']) ?>
  • <?= $this->Html->link(__('New Location'), ['controller' => 'Locations', 'action' => 'add']) ?>
  • <?= $this->Html->link(__('List Clients'), ['controller' => 'Clients', 'action' => 'index']) ?>
  • <?= $this->Html->link(__('New Client'), ['controller' => 'Clients', 'action' => 'add']) ?>

<?= h($staff->id) ?>

    <tr>
        <th scope="row"><?= __('Dusername') ?></th>
        <td><?= h($staff->dusername) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Susername') ?></th>
        <td><?= h($staff->susername) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Firstname') ?></th>
        <td><?= h($staff->firstname) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Lastname') ?></th>
        <td><?= h($staff->lastname) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Password') ?></th>
        <td><?= h($staff->password) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Type') ?></th>
        <td><?= h($staff->type) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Sex') ?></th>
        <td><?= h($staff->sex) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Location') ?></th>
        <td><?= $staff->has('location') ? $this->Html->link($staff->location->id, ['controller' => 'Locations', 'action' => 'view', $staff->location->id]) : '' ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Email') ?></th>
        <td><?= h($staff->email) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Phone') ?></th>
        <td><?= h($staff->phone) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Id') ?></th>
        <td><?= $this->Number->format($staff->id) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Depth') ?></th>
        <td><?= $this->Number->format($staff->depth) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Age') ?></th>
        <td><?= $this->Number->format($staff->age) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Created') ?></th>
        <td><?= h($staff->created) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Modified') ?></th>
        <td><?= h($staff->modified) ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Grouper') ?></th>
        <td><?= $staff->grouper ? __('Yes') : __('No'); ?></td>
    </tr>
    <tr>
        <th scope="row"><?= __('Recontacter') ?></th>
        <td><?= $staff->recontacter ? __('Yes') : __('No'); ?></td>
    </tr>
</table>
<div class="related">
    <h4><?= __('Related Clients') ?></h4>
    <?php if (!empty($staff->clients)): ?>
    <table cellpadding="0" cellspacing="0">
        <tr>
            <th scope="col"><?= __('Id') ?></th>
            <th scope="col"><?= __('Username') ?></th>
            <th scope="col"><?= __('Sex') ?></th>
            <th scope="col"><?= __('Location Id') ?></th>
            <th scope="col"><?= __('Age') ?></th>
            <th scope="col"><?= __('Created') ?></th>
            <th scope="col"><?= __('Modified') ?></th>
            <th scope="col" class="actions"><?= __('Actions') ?></th>
        </tr>
        <?php foreach ($staff->clients as $clients): ?>
        <tr>
            <td><?= h($clients->id) ?></td>
            <td><?= h($clients->username) ?></td>
            <td><?= h($clients->sex) ?></td>
            <td><?= h($clients->location_id) ?></td>
            <td><?= h($clients->age) ?></td>
            <td><?= h($clients->created) ?></td>
            <td><?= h($clients->modified) ?></td>
            <td class="actions">
                <?= $this->Html->link(__('View'), ['controller' => 'Clients', 'action' => 'view', $clients->id]) ?>
                <?= $this->Html->link(__('Edit'), ['controller' => 'Clients', 'action' => 'edit', $clients->id]) ?>
                <?= $this->Form->postLink(__('Delete'), ['controller' => 'Clients', 'action' => 'delete', $clients->id], ['confirm' => __('Are you sure you want to delete # {0}?', $clients->id)]) ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </table>
    <?php endif; ?>
</div>

regards

So, you deleted some related client columns from the staff view template,
and they are still showing when you view a particular staff member?

You may need to check for caching. In the browser, ensure caching is
disabled. Check there are not any cached views in app/tmp/cache/views.

Also make sure you are hitting the right action and view. Use Xdebug to
trace it through, or logging in the controller and view to ensure they
right ones are being hit.

Hi,

I was changing view.ctp, but, it’s index.ctp that’s being displayed ( not view.ctp )
what is view.ctp used for?

oh well, I only wasted 4 days; to change something trivial.

By the way, how do I remove that stupid red strip that’s displayed at the bottome of the screen?

regards

The view.ctp is used when you are looking at a single record, rather than a list of records.

With regards to the red strip, locate the HTML and CSS and remove it from there. If it’s on all the screens, most likely it’s in the layout.ctp. If it’s only a few screens, then it will be a part of the view template for that screen.

The red strip is likely the debug toolbar for CakePHP (DebugKit). You can click the Cake icon to minimize it. If you want to remove the plugin entirely, delete Plugin::load('DebugKit', ['bootstrap' => true]); from your application’s config/bootstrap.php file.