Joomla Backend List Layout File

The layout file, default.php, displays the list of records or items in tabular format. This list of items is obtained by the view file from the model as array of objects.

The layout file for backend list contains items inside the form for the toolbar action buttons and filter form.

  1. If the items are empty, display a message instead of items.
  2. In the table, add a column for checkboxes. Generally, this is the first column. This column is used to perform actions (like publish, unpublish, delete) on multiple rows.
  3. Create a link on the title to edit the item.

Step 1: Opening Form Tag

<form action="<?php echo Route::_('index.php?option=com_stars&view=planets'); ?>" 
method="post" name="adminForm" id="adminForm">

Step 2: No Items Message

You can add the following code just below the opening form tag.

<?php if (empty($this->items)) : ?>
  <div class="alert alert-info">
      <span class="icon-info-circle" aria-hidden="true"></span>
      <?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
  </div>
<?php else : ?>

Step 3: Table for Items

Table is displayed if there the items are not empty. The first column displays a checkbox using the HTMLHelper class.

<table class="table table-striped table-hover">
  <thead>
      <tr>
          <th><?php echo HTMLHelper::_('grid.checkall'); ?></th>
          <th>Status</th>
          <th>Title</th>
          <th>ID</th>
      </tr>
  </thead>
  <tbody>
  <?php foreach ($this->items as $i => $item) : ?>
      <tr>
          <td><?php echo HTMLHelper::_('grid.id', $i, $item->id); ?></td>
          <td><?php echo $item->published; ?></td>
          <td><?php echo $item->title; ?></td>
          <td><?php echo $item->id; ?></td>
      </tr>
  <?php endforeach; ?>
  </tbody>
</table>
<?php endif; ?>

Step 4: Closing Form

Finally, the form tag is closed.

    <input type="hidden" name="task" value="">
    <input type="hidden" name="boxchecked" value="0">
    <?php echo HTMLHelper::_('form.token'); ?>
</form>

A token is added to prevent CSRF attacks.

Step 5: Create Edit Link for Title

To make the link for the title for editing the record, replace the table data column for the title.

<td>
<a href="/<?php echo Route::_('index.php?option=com_stars&task=planet.edit&id=' . (int) $item->id); ?>" title="<?php echo Text::_('JACTION_EDIT'); ?>"> 
    <?php echo $this->escape($item->title); ?>
</a>
</td>

After clicking the link, Joomla calls the edit() method of Planet Controller. This method is defined in the parent class FormCotroller.