Joomla 后端分页在自定义 MVC 应用程序中不起作用

发布于 2024-12-04 01:44:53 字数 12533 浏览 0 评论 0原文

Joomla 后端分页在自定义 MVC 应用程序中不起作用

显示页面总数,但从分页 getListFooter() 按下的任何控件;失败并运行回初始屏幕“ /administrator /index.php? option = com_agmanage”

这很令人困惑,因为 $this->分页-> getRowOffset($i);正确显示。

这是默认视图:

    <?php
/**
* @version 1.0
* @package agmanage 1.0.0
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');
jimport('joomla.html.pane');

class agmanageViewConfiguration extends JView
{
    function display($tpl = null)
    {
        global $mainframe;

        JToolBarHelper::title('Agility Eye Management','agmanage');

        JSubMenuHelper::addEntry(JText::_('Results'), 'index.php?option=com_agmanage&view=memberships');
        JSubMenuHelper::addEntry(JText::_('View Dogs Handlers & Subscribers'), 'index.php?option=com_agmanage&view=transactions');
        JSubMenuHelper::addEntry(JText::_('Database Administration'), 'index.php?option=com_agmanage&view=configuration', true);
        JSubMenuHelper::addEntry(JText::_('Manage Users'), 'index.php?option=com_rsmembership&view=users');
        JSubMenuHelper::addEntry(JText::_('Back to Splashscreen'), 'index.php?option=com_agmanage', true);

        $task = JRequest::getVar('task','');    

        JToolBarHelper::apply();
        JToolBarHelper::save();
        JToolBarHelper::cancel();

        $config = agmanageHelper::getConfig();
        $this->assignRef('config', $config);

        $pane =& JPane::getInstance('Tabs', array(), true);
        $this->assignRef('pane', $pane);

        $this->assignRef('sortColumn', JRequest::getVar('filter_order','date'));
        $this->assignRef('sortOrder', JRequest::getVar('filter_order_Dir','DESC'));

        $this->assignRef('configuration', $this->get('configuration'));

        $this->assignRef('cache', $this->get('cache'));

        $this->assignRef('pagination', $this->get('pagination'));

        $filter_word = JRequest::getString('search', '');
        $this->assignRef('filter_word', $filter_word);

        parent::display($tpl);
    }
}

这是由它运行的模板 ( $ tpl ) :

<?php
/**
* @version 1.0
* @package agmanage 1.0.0
*/

defined('_JEXEC') or die('Restricted access');

JHTML::_('behavior.tooltip');
?>
<form action="index.php?option=com_agmanage&view=configuration" method="post" name="adminForm" id="adminForm">
<?php
echo $this->pane->startPane('configuration-pane');

echo $this->pane->startPanel(JText::_('Edit Dogs'), 'configuration-patches');
?>
<div class="col100">
    <? /* START OF EDIT DOGS */?>
    <table class="adminform">
        <tr>
            <td width="100%">
                <?php echo JText::_( 'Search (By Dog name)' ); ?>
                <input type="text" name="search" id="search" value="<?php echo $this->filter_word; ?>" class="text_area" onChange="document.adminForm.submit();" />
                <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
                <button onclick="this.form.getElementById('search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
            </td>
            <td nowrap="nowrap">&nbsp;</td>
        </tr>
    </table>
    <div id="editcell1">
        <table class="adminlist">
            <thead>
                <tr>
                    <th width="5"><?php echo JText::_( '#' ); ?></th>
                    <th><?php echo JText::_( 'Dog Name' ); ?></th>
                    <th width="100"><?php echo JText::_('Status'); ?></th>
                    <th width="5"><?php echo JText::_('ABC'); ?></th>
                    <th width="150"><?php echo JText::_('Club'); ?></th>
                    <th width="140"><?php echo JText::_('Usual Handler'); ?></th>
                    <th><?php echo JText::_('Subscriber'); ?></th>
                    <th width="5"><?php echo JText::_( 'Edit' ); ?></th>

                </tr>
            </thead>
    <?php
    $k = 0;
    $i = 0;
    $n = count($this->configuration);
    foreach ($this->configuration as $row)

    {
    ?>
        <tr class="row<?php echo $k; ?>">
            <td align="center"><?php echo $this->pagination->getRowOffset($i); ?></td>
            <td align="center"><?php echo $row->DogName; ?></td>
            <td align="center"><?php echo $row->StatusCode; ?></td>
            <td align="center">
            <?php 
            if ($row->ABC=="1")
                echo "Yes";
            else
                echo "No";

            ?>
            </td>
            <td align="center">
            <?php 
            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->Clubcode;
                //echo $temp;
                $result = mysql_query("SELECT * FROM club WHERE Clubcode=$temp") or die(mysql_error());

                while($new = mysql_fetch_array($result))
                 {
                 echo $new['Club'];
                 }

                mysql_close($con);
            ?>
            </td>
            <td align="center"><?php 

            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->HandlerId;
                //echo $temp;
                $result = mysql_query("SELECT * FROM handlers WHERE handlerId=$temp") or die(mysql_error());

                while($new1 = mysql_fetch_array($result))
                 {
                 echo $new1['HandlerFore'] . " " . $new1['HandlerSur'];
                 }

                mysql_close($con);

            ?></td>
            <td align="center"><?php 

            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->Subcode;
                echo $temp;
                $result = mysql_query("SELECT * FROM jos_users WHERE calluser=$temp") or die(mysql_error());

                while($new2 = mysql_fetch_array($result))
                 {
                 echo " - ";
                 echo $new2['name'];     
                 }

                mysql_close($con);

            ?></td>

            <td><a href="<?php //echo JRoute::_('index.php?option=com_agmanage&controller=configuration&task=edit&handler='.$row->Subcode.'&dog='.$row->Dogcode); ?>"><IMG src="http://www.agilityeye.co.uk.juliet.webhoster.co.uk/images/M_images/edit.png"></a></td>

        </tr>
    <?php
        $i++;
        $k=1-$k;
    }
    ?>
        <tfoot>
            <tr>
                <td colspan="12"><?php echo $this->pagination->getListFooter(); ?></td>
            </tr>
        </tfoot>
        </table>
    </div>

    <?php echo JHTML::_( 'form.token' ); ?>
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="option" value="com_agmanage" />
    <input type="hidden" name="view" value="configuration" />
    <input type="hidden" name="controller" value="configuration" />
    <input type="hidden" name="task" value="" />

    <? /* END OF EDIT DOGS */?>
    </fieldset>
</div>
<div class="clr"></div>
<?php
echo $this->pane->endPanel();

echo $this->pane->startPanel(JText::_('New Tab'), 'new');
?>
<div class="col100">
    <fieldset class="adminform">
        <table class="admintable">
        <tr> Spacer</tr>
        </table>
    </fieldset>
</div>
<div class="clr"></div>
<?php
echo $this->pane->endPanel();

echo $this->pane->endPane();
?>

<?php echo JHTML::_('form.token'); ?>
<input type="hidden" name="option" value="com_agmanage" />
<input type="hidden" name="view" value="agmanage" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="configuration" />
</form>

<script type="text/javascript">
function rsm_enable_registration(what)
{
    if (what == 1)
        $('registration_page').disabled = false;
    else
        $('registration_page').disabled = true;
}
</script>

<?php
//keep session alive while editing
JHTML::_('behavior.keepalive');
?>

以及模型:

        <?php
        /**
        * @version 1.0
        * @package agmanage 1.0.0
        */

        defined('_JEXEC') or die('Restricted access');

        jimport('joomla.application.component.model');

        class agmanageModelConfiguration extends JModel
{
    var $_data = null;
    var $_total = 0;
    var $_query = '';
    var $_pagination = null;
    var $_db = null;

    var $_id = 0;

    function __construct()
    {
        parent::__construct();
        $this->_db = JFactory::getDBO();
        $this->_query = $this->_buildQuery();

        global $mainframe, $option;

        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest($option.'.configuration.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = $mainframe->getUserStateFromRequest($option.'.configuration.limitstart', 'limitstart', 0, 'int');

        // In case limit has been changed, adjust it
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);

        $this->setState($option.'.configuration.limit', $limit);
        $this->setState($option.'.configuration.limitstart', $limitstart);
    }

    function _buildQuery()
    {
        global $mainframe;

        //$query = "SELECT t.*, IFNULL(u.email, t.user_email) AS email FROM #__agmanage_configuration t LEFT JOIN #__users u ON (`t`.`user_id`=`u`.`id`)";
        $query = "SELECT * FROM dog";

        $filter_word = JRequest::getString('search', '');
        if (!empty($filter_word))
            $query .= " WHERE DogName LIKE '%".$filter_word."%'";
        /*
        $sortColumn = JRequest::getVar('filter_order', 'date');
        $sortColumn = $this->_db->getEscaped($sortColumn);

        $sortOrder = JRequest::getVar('filter_order_Dir', 'DESC');
        $sortOrder = $this->_db->getEscaped($sortOrder);

        $query .= " ORDER BY ".$sortColumn." ".$sortOrder;
        */
        return $query;
    }

    function getConfiguration()
    {
        global $option;

        if (empty($this->_data))
            $this->_data = $this->_getList($this->_query, $this->getState($option.'.configuration.limitstart'), $this->getState($option.'.configuration.limit'));

        return $this->_data;
    }

    function getTotal()
    {
        if (empty($this->_total))
            $this->_total = $this->_getListCount($this->_query); 

        return $this->_total;
    }

    function getPagination()
    {
        if (empty($this->_pagination))
        {
            global $option;
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState($option.'.configuration.limitstart'), $this->getState($option.'.configuration.limit'));
        }

        return $this->_pagination;
    }

    function remove($cids)
    {
        $cids = implode(',', $cids);

        $query = "DELETE FROM #__agmanage_configuration WHERE `id` IN (".$cids.")";
        $this->_db->setQuery($query);
        $this->_db->query();

        return true;
    }

    function getCache()
    {
        return agmanageHelper::getCache();
    }
        }
        ?>

Joomla Back-end Pagination not working in custom MVC Application

Shows total number of pages but any control pressed from the pagination getListFooter() ; fails and runs back to the splash screen " /administrator /index.php? option = com_agmanage"

It's confusing, as $this-> pagination-> getRowOffset($i); correctly displays.

Here's the default view:

    <?php
/**
* @version 1.0
* @package agmanage 1.0.0
*/

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');
jimport('joomla.html.pane');

class agmanageViewConfiguration extends JView
{
    function display($tpl = null)
    {
        global $mainframe;

        JToolBarHelper::title('Agility Eye Management','agmanage');

        JSubMenuHelper::addEntry(JText::_('Results'), 'index.php?option=com_agmanage&view=memberships');
        JSubMenuHelper::addEntry(JText::_('View Dogs Handlers & Subscribers'), 'index.php?option=com_agmanage&view=transactions');
        JSubMenuHelper::addEntry(JText::_('Database Administration'), 'index.php?option=com_agmanage&view=configuration', true);
        JSubMenuHelper::addEntry(JText::_('Manage Users'), 'index.php?option=com_rsmembership&view=users');
        JSubMenuHelper::addEntry(JText::_('Back to Splashscreen'), 'index.php?option=com_agmanage', true);

        $task = JRequest::getVar('task','');    

        JToolBarHelper::apply();
        JToolBarHelper::save();
        JToolBarHelper::cancel();

        $config = agmanageHelper::getConfig();
        $this->assignRef('config', $config);

        $pane =& JPane::getInstance('Tabs', array(), true);
        $this->assignRef('pane', $pane);

        $this->assignRef('sortColumn', JRequest::getVar('filter_order','date'));
        $this->assignRef('sortOrder', JRequest::getVar('filter_order_Dir','DESC'));

        $this->assignRef('configuration', $this->get('configuration'));

        $this->assignRef('cache', $this->get('cache'));

        $this->assignRef('pagination', $this->get('pagination'));

        $filter_word = JRequest::getString('search', '');
        $this->assignRef('filter_word', $filter_word);

        parent::display($tpl);
    }
}

Here's the template that gets run by it ( $ tpl ) :

<?php
/**
* @version 1.0
* @package agmanage 1.0.0
*/

defined('_JEXEC') or die('Restricted access');

JHTML::_('behavior.tooltip');
?>
<form action="index.php?option=com_agmanage&view=configuration" method="post" name="adminForm" id="adminForm">
<?php
echo $this->pane->startPane('configuration-pane');

echo $this->pane->startPanel(JText::_('Edit Dogs'), 'configuration-patches');
?>
<div class="col100">
    <? /* START OF EDIT DOGS */?>
    <table class="adminform">
        <tr>
            <td width="100%">
                <?php echo JText::_( 'Search (By Dog name)' ); ?>
                <input type="text" name="search" id="search" value="<?php echo $this->filter_word; ?>" class="text_area" onChange="document.adminForm.submit();" />
                <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
                <button onclick="this.form.getElementById('search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
            </td>
            <td nowrap="nowrap"> </td>
        </tr>
    </table>
    <div id="editcell1">
        <table class="adminlist">
            <thead>
                <tr>
                    <th width="5"><?php echo JText::_( '#' ); ?></th>
                    <th><?php echo JText::_( 'Dog Name' ); ?></th>
                    <th width="100"><?php echo JText::_('Status'); ?></th>
                    <th width="5"><?php echo JText::_('ABC'); ?></th>
                    <th width="150"><?php echo JText::_('Club'); ?></th>
                    <th width="140"><?php echo JText::_('Usual Handler'); ?></th>
                    <th><?php echo JText::_('Subscriber'); ?></th>
                    <th width="5"><?php echo JText::_( 'Edit' ); ?></th>

                </tr>
            </thead>
    <?php
    $k = 0;
    $i = 0;
    $n = count($this->configuration);
    foreach ($this->configuration as $row)

    {
    ?>
        <tr class="row<?php echo $k; ?>">
            <td align="center"><?php echo $this->pagination->getRowOffset($i); ?></td>
            <td align="center"><?php echo $row->DogName; ?></td>
            <td align="center"><?php echo $row->StatusCode; ?></td>
            <td align="center">
            <?php 
            if ($row->ABC=="1")
                echo "Yes";
            else
                echo "No";

            ?>
            </td>
            <td align="center">
            <?php 
            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->Clubcode;
                //echo $temp;
                $result = mysql_query("SELECT * FROM club WHERE Clubcode=$temp") or die(mysql_error());

                while($new = mysql_fetch_array($result))
                 {
                 echo $new['Club'];
                 }

                mysql_close($con);
            ?>
            </td>
            <td align="center"><?php 

            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->HandlerId;
                //echo $temp;
                $result = mysql_query("SELECT * FROM handlers WHERE handlerId=$temp") or die(mysql_error());

                while($new1 = mysql_fetch_array($result))
                 {
                 echo $new1['HandlerFore'] . " " . $new1['HandlerSur'];
                 }

                mysql_close($con);

            ?></td>
            <td align="center"><?php 

            $con = mysql_connect("**********************");
            if (!$con)
                {
                die('Could not connect: ' . mysql_error());
                }

                mysql_select_db("agilityeye", $con);
                $temp=$row->Subcode;
                echo $temp;
                $result = mysql_query("SELECT * FROM jos_users WHERE calluser=$temp") or die(mysql_error());

                while($new2 = mysql_fetch_array($result))
                 {
                 echo " - ";
                 echo $new2['name'];     
                 }

                mysql_close($con);

            ?></td>

            <td><a href="<?php //echo JRoute::_('index.php?option=com_agmanage&controller=configuration&task=edit&handler='.$row->Subcode.'&dog='.$row->Dogcode); ?>"><IMG src="http://www.agilityeye.co.uk.juliet.webhoster.co.uk/images/M_images/edit.png"></a></td>

        </tr>
    <?php
        $i++;
        $k=1-$k;
    }
    ?>
        <tfoot>
            <tr>
                <td colspan="12"><?php echo $this->pagination->getListFooter(); ?></td>
            </tr>
        </tfoot>
        </table>
    </div>

    <?php echo JHTML::_( 'form.token' ); ?>
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="option" value="com_agmanage" />
    <input type="hidden" name="view" value="configuration" />
    <input type="hidden" name="controller" value="configuration" />
    <input type="hidden" name="task" value="" />

    <? /* END OF EDIT DOGS */?>
    </fieldset>
</div>
<div class="clr"></div>
<?php
echo $this->pane->endPanel();

echo $this->pane->startPanel(JText::_('New Tab'), 'new');
?>
<div class="col100">
    <fieldset class="adminform">
        <table class="admintable">
        <tr> Spacer</tr>
        </table>
    </fieldset>
</div>
<div class="clr"></div>
<?php
echo $this->pane->endPanel();

echo $this->pane->endPane();
?>

<?php echo JHTML::_('form.token'); ?>
<input type="hidden" name="option" value="com_agmanage" />
<input type="hidden" name="view" value="agmanage" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="configuration" />
</form>

<script type="text/javascript">
function rsm_enable_registration(what)
{
    if (what == 1)
        $('registration_page').disabled = false;
    else
        $('registration_page').disabled = true;
}
</script>

<?php
//keep session alive while editing
JHTML::_('behavior.keepalive');
?>

And the Model:

        <?php
        /**
        * @version 1.0
        * @package agmanage 1.0.0
        */

        defined('_JEXEC') or die('Restricted access');

        jimport('joomla.application.component.model');

        class agmanageModelConfiguration extends JModel
{
    var $_data = null;
    var $_total = 0;
    var $_query = '';
    var $_pagination = null;
    var $_db = null;

    var $_id = 0;

    function __construct()
    {
        parent::__construct();
        $this->_db = JFactory::getDBO();
        $this->_query = $this->_buildQuery();

        global $mainframe, $option;

        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest($option.'.configuration.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = $mainframe->getUserStateFromRequest($option.'.configuration.limitstart', 'limitstart', 0, 'int');

        // In case limit has been changed, adjust it
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);

        $this->setState($option.'.configuration.limit', $limit);
        $this->setState($option.'.configuration.limitstart', $limitstart);
    }

    function _buildQuery()
    {
        global $mainframe;

        //$query = "SELECT t.*, IFNULL(u.email, t.user_email) AS email FROM #__agmanage_configuration t LEFT JOIN #__users u ON (`t`.`user_id`=`u`.`id`)";
        $query = "SELECT * FROM dog";

        $filter_word = JRequest::getString('search', '');
        if (!empty($filter_word))
            $query .= " WHERE DogName LIKE '%".$filter_word."%'";
        /*
        $sortColumn = JRequest::getVar('filter_order', 'date');
        $sortColumn = $this->_db->getEscaped($sortColumn);

        $sortOrder = JRequest::getVar('filter_order_Dir', 'DESC');
        $sortOrder = $this->_db->getEscaped($sortOrder);

        $query .= " ORDER BY ".$sortColumn." ".$sortOrder;
        */
        return $query;
    }

    function getConfiguration()
    {
        global $option;

        if (empty($this->_data))
            $this->_data = $this->_getList($this->_query, $this->getState($option.'.configuration.limitstart'), $this->getState($option.'.configuration.limit'));

        return $this->_data;
    }

    function getTotal()
    {
        if (empty($this->_total))
            $this->_total = $this->_getListCount($this->_query); 

        return $this->_total;
    }

    function getPagination()
    {
        if (empty($this->_pagination))
        {
            global $option;
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState($option.'.configuration.limitstart'), $this->getState($option.'.configuration.limit'));
        }

        return $this->_pagination;
    }

    function remove($cids)
    {
        $cids = implode(',', $cids);

        $query = "DELETE FROM #__agmanage_configuration WHERE `id` IN (".$cids.")";
        $this->_db->setQuery($query);
        $this->_db->query();

        return true;
    }

    function getCache()
    {
        return agmanageHelper::getCache();
    }
        }
        ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2024-12-11 01:44:53

如果删除分页,所有内容都可以正常显示吗?首先确保它在没有分页的情况下也能工作,这样你就不会去追寻不存在的问题。如果没有,则在 Joomla 文档中逐步实施 - http://docs.joomla.org/在您的组件中使用_JPagination

If you remove the pagination does everything display properly? Make sure it works without the pagination first so you don't go chasing a problem that isn't there. If it works without, then do the step by step implementation in the Joomla docs - http://docs.joomla.org/Using_JPagination_in_your_component

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文