web-dev-qa-db-fra.com

Joomla 3 Backend Pagination montrant les résultats complets à la place

Je crée un nouveau composant et ai suivi le didacticiel Joomla 3 MVC ( détails ), mais je ne parviens pas à faire fonctionner la pagination. Fait intéressant, lorsque j'implémente le composant HelloWorld lié à ce tutoriel, sa pagination ne fonctionne pas non plus - je sais donc que je n'ai rien manqué.

Le bas de page de pagination peut s'afficher au bas de la page, mais lorsque je clique sur le numéro suivant/final/un numéro de page réel, il affiche simplement tous les enregistrements, puis supprime le pied de page de pagination. Qu'est-ce que je rate?

modèles/danceregs.php

class DanceRegModelDanceRegs extends JModelList
{
/**
 * Constructor.
 *
 * @param   array  $config  An optional associative array of configuration settings.
 *
 * @see     JController
 * @since   1.6
 */
public function __construct($config = array())
{
    if (empty($config['filter_fields']))
    {
        $config['filter_fields'] = array(
            'dancer_id','d.dancer_id',
            'dancer_name','d.dancer_name',
            'studio', 'd.studio_id',
            'current_age','d.current_age',
            'published','d.published'
        );
    }

    parent::__construct($config);
}

/**
 * Method to build an SQL query to load the list data.
 *
 * @return      string  An SQL query
 */
protected function getListQuery()
{
    // Initialize variables.
    $db    = JFactory::getDbo();
    $query = $db->getQuery(true);

    // Create the base select statement.
    $query->select('*, (YEAR(CURDATE())-YEAR(dancer_birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(dancer_birthdate,5)) AS current_age')
          ->from($db->quoteName('#__registration_dancers'));

    // Filter: like / search
    $search = $this->getState('filter.search');

    if (!empty($search))
    {
        $like = $db->quote('%' . $search . '%');
        $query->where('dancer_name LIKE ' . $like);
    }

    // Filter by studio name
    $studio_id = $this->getState('filter.studio_id');

    if (is_numeric($studio_id))
    {
        $query->where('studio_id = ' . (int) $studio_id);
    }
    elseif ($studio_id === '')
    {
        //$query->where('(published IN (0, 1))');
    }

    // Filter by published state
    $published = $this->getState('filter.published');

    if (is_numeric($published))
    {
        $query->where('published = ' . (int) $published);
    }
    elseif ($published === '')
    {
        $query->where('(published IN (0, 1))');
    }

    // Add the list ordering clause.
    $orderCol   = $this->state->get('list.ordering', 'dancer_id');
    $orderDirn  = $this->state->get('list.direction', 'desc');

    $query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));

    return $query;
}
}

views/danceregs/tmpl/default.php

<form action="index.php?option=com_dancereg&view=danceregs" method="post" id="adminForm" name="adminForm">
<div class="row-fluid">
    <div class="span6">
        <?php echo JText::_('COM_DANCEREG_DANCEREGS_FILTER'); ?>
        <?php
            echo JLayoutHelper::render(
                'joomla.searchtools.default',
                array('view' => $this)
            );
        ?>
    </div>
</div>
<table class="table table-striped table-hover">
    <thead>
    <tr>
        <th width="2%"><?php echo JText::_('COM_DANCEREG_NUM'); ?></th>
        <th width="2%">
            <?php echo JHtml::_('grid.checkall'); ?>
        </th>
        <th width="30%">
            <?php echo JHtml::_('grid.sort', 'COM_DANCEREG_DANCEREGS_NAME', 'dancer_name', $listDirn, $listOrder); ?>
        </th>
        <th width="35%">
            <?php echo JHtml::_('grid.sort', 'COM_DANCEREG_STUDIO_NAME', 'studio_id', $listDirn, $listOrder); ?>
        </th>
        <th width="10%">
            <?php echo JHtml::_('grid.sort', 'DOB_AGE', 'current_age', $listDirn, $listOrder); ?>
        </th>
        <th width="10%">
            <?php echo JText::_('AGE'); ?>
        </th>
        <th width="5%">
            <?php echo JHtml::_('grid.sort', 'COM_DANCEREG_PUBLISHED', 'published', $listDirn, $listOrder); ?>
        </th>
        <th width="7%">
            <?php echo JHtml::_('grid.sort', 'COM_DANCEREG_ID', 'dancer_id', $listDirn, $listOrder); ?>
        </th>
    </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="5">
                <?php echo $this->pagination->getListFooter(); ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
        <?php if (!empty($this->items)) : ?>
            <?php foreach ($this->items as $i => $row) :
                //$link = JRoute::_('index.php?option=com_dancereg&task=dancereg.edit&id=' . $row->dancer_id);
                $link = JRoute::_('index.php?option=com_dancereg&view=dancereg&layout=edit&dancer_id=' . $row->dancer_id);
                $studio_link = JRoute::_('index.php?option=com_comprofiler&view=edit&cid=' . $row->studio_id . '#cbtabpane11');
            ?>
                <tr>
                    <td><?php echo $this->pagination->getRowOffset($i); ?></td>
                    <td>
                        <?php echo JHtml::_('grid.id', $i, $row->dancer_id); ?>
                    </td>
                    <td>
                        <a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_DANCEREG_EDIT_DANCEREG'); ?>">
                            <?php echo $row->dancer_name; ?>
                        </a>
                    </td>
                    <td>
                        <a href="<?php echo $studio_link; ?>" title="<?php echo JText::_('COM_DANCEREG_EDIT_STUDIO'); ?>">
                            <?php echo $studdets[$row->studio_id]; ?>
                        </a>
                    </td>
                    <td align="center">
                        <?php echo $row->current_age; ?>
                    </td>
                    <td align="center">
                        <?php echo $DB_sitekore->getAge($row->dancer_birthdate); ?>
                    </td>
                    <td align="center">
                        <?php echo JHtml::_('jgrid.published', $row->published, $i, 'danceregs.', true, 'cb'); ?>
                    </td>
                    <td align="center">
                        <?php echo $row->dancer_id; ?>
                    </td>
                </tr>

                <?
                $clean_dancers = str_replace(',',' ',$row->dancer_name);
                $clean_studio = str_replace(',',' ',$studdets[$row->studio_id]);

                // used for generating our CSV file for Excel
                $csv_output .= $row->dancer_id.",".$clean_dancers.",".$clean_studio.",".$row->current_age.",".$DB_sitekore->getAge($row->dancer_birthdate)
                .",".$row->datemodified."\n";
                ?>
            <?php endforeach; ?>
        <?php endif; ?>
    </tbody>
</table>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>"/>
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>"/>
<?php echo JHtml::_('form.token'); ?>

views/danceregs/view.html.php

class DanceRegViewDanceRegs extends JViewLegacy
{
/**
 * Display the Dancer Registration view
 *
 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 *
 * @return  void
 */
function display($tpl = null)
{

    // Get application
    $app = JFactory::getApplication();
    $context = "dancereg.list.admin.dancereg";
    // Get data from the model
    $this->items        = $this->get('Items');
    $this->pagination   = $this->get('Pagination');
    $this->state        = $this->get('State');
    $this->filter_order = $app->getUserStateFromRequest($context.'filter_order', 'filter_order', 'dancer_id', 'cmd');
    $this->filter_order_Dir = $app->getUserStateFromRequest($context.'filter_order_Dir', 'filter_order_Dir', 'desc', 'cmd');
    $this->filterForm       = $this->get('FilterForm');
    $this->activeFilters    = $this->get('ActiveFilters');

    // What Access Permissions does this user have? What can (s)he do?
    $this->canDo = DanceRegHelper::getActions();

    // Check for errors.
    if (count($errors = $this->get('Errors')))
    {
        JError::raiseError(500, implode('<br />', $errors));

        return false;
    }

    // Set the submenu
    DanceRegHelper::addSubmenu('danceregs');

    // Set the toolbar and number of found items
    $this->addToolBar();

    // Display the template
    parent::display($tpl);

    // Set the document
    $this->setDocument();
}

/**
 * Add the page title and toolbar.
 *
 * @return  void
 *
 * @since   1.6
 */
protected function addToolBar()
{
    $title = JText::_('COM_DANCEREG_MANAGER_DANCEREGS');

    if ($this->pagination->total)
    {
        $title .= "<span style='font-size: 0.5em; vertical-align: middle;padding-left:5px;'>(" . $this->pagination->total . ")</span>";
    }

    JToolBarHelper::title($title, 'dancereg');

    if ($this->canDo->get('core.create')) 
    {
        JToolBarHelper::addNew('dancereg.add', 'JTOOLBAR_NEW');
    }
    if ($this->canDo->get('core.edit')) 
    {
        JToolBarHelper::editList('dancereg.edit', 'JTOOLBAR_EDIT');
    }
    if ($this->canDo->get('core.delete')) 
    {
        JToolBarHelper::deleteList('', 'danceregs.delete', 'JTOOLBAR_DELETE');
    }
    if ($this->canDo->get('core.admin')) 
    {
        JToolBarHelper::divider();
        JToolBarHelper::preferences('com_dancereg');
    }
}
/**
 * Method to set up the document properties
 *
 * @return void
 */
protected function setDocument() 
{
    $document = JFactory::getDocument();
    $document->setTitle(JText::_('COM_DANCEREG_ADMINISTRATION'));
}
}
1
Mhaddy

Il s'avère que ce qui me manquait était le suivant de mon\models\forms\filter_componentnames.xml:

<fields name="list">
    <field
        name="limit"
        type="limitbox"
        class="input-mini"
        default="25"
        label="COM_CONTENT_LIST_LIMIT"
        description="COM_CONTENT_LIST_LIMIT_DESC"
        onchange="this.form.submit();"
    />
</fields>

Après avoir ajouté ceci, la pagination a fonctionné. J'espère que cela aide quelqu'un!

1
Mhaddy