Joomla 3分页:页脚不起作用

时间:2014-10-26 11:04:13

标签: php joomla pagination

我正在将后端组件从Joomla 1.5迁移到Joomla 3.3.3

组件基本上只显示存储在数据库中的一些数据。也可以过滤项目列表。

一切正常,除了分页问题:基本上,页脚不起作用。如果我尝试点击它来查看不同于1的页面,则没有任何反应。但是,如果那时我也点击搜索或重置按钮,那么它可以工作。

以下是代码:

型号:

<?php
defined('_JEXEC') or die( 'Restricted access' );

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

class mobileactivationmobilevalidateModelmobilevalidate extends JModelLegacy
{
    var $_data = null;
    
    var $_total = null;
    
    var $_pagination = null;
    
    /**
     * Construct a Mobile evaluation model
    **/
    function __construct()
    {
        //global $mainframe, $option;
        //Migration modification
        $mainframe = JFactory::getApplication();
        $option = JRequest::getCmd('option');

        parent::__construct();
        
        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest('global.list.limit','limit', $mainframe->getCfg('list_limit'));
        $limitstart = $mainframe->getUserStateFromRequest("'$option'.mobilevalidate.limitstart",'limitstart',0);
        
        // Set the state pagination variables
        $this->setState('limit', $limit);
        $this->setState('limitstart',$limitstart);
    }
    /**
     * Build up the query for showing the entries
     * uses filters: search, validate status, paging, ordering
    **/
    function _buildQuery()
    {
        $option = JRequest::getCmd('option');
        $mainframe = JFactory::getApplication();

        $filter_validated = $mainframe->getUserStateFromRequest("'$option'.filter_validated",'filter_validated','-1');
        $filter_search = $mainframe->getUserStateFromRequest("'$option'.filter_search",'filter_search');

        $query = 'SELECT a.`username`, b.`name`, `code`, `send`, `validated` '
               . 'FROM `r2n_mobilevalidate` a, `#__users` b '
			   . 'WHERE a.username = b.username '
               . $this->_buildQueryWhere()
               . $this->_buildQueryOrderBy();
        return $query;
    }
    
    /**
     * Build filter part of the query
     * filters: search, validate status, paging
    **/
    function _buildQueryWhere()
    {
        //global $mainframe, $option;
        // Get the filter values
        
        //Migration modification
        $option = JRequest::getCmd('option');
        $mainframe = JFactory::getApplication();

        $filter_validated = $mainframe->getUserStateFromRequest("'$option'.filter_validated",'filter_validated','-1');
        $filter_search = $mainframe->getUserStateFromRequest("'$option'.filter_search",'filter_search');
        
        // Prepare the WHERE clause
        $where = array();
        // Determine published state
        if ($filter_validated >= 0)
        {
            $where[] = "validated = '$filter_validated'";
        }
        // Determine search terms
        if ($filter_search = trim($filter_search))
        {
            //$filter_search = JString::strtolower($filter_search);
            $db =& JFactory::getDBO();
            $filter_search = $db->escape($filter_search);
            $where[] = '(a.username LIKE "%'.$filter_search.'%" OR b.name LIKE "%'.$filter_search.'%")';
        }

        // Return the WHERE clause
        return ($where) ? ' AND '.implode(' AND ', $where) : '';
    }
    
    /**
     * Build ordering part of query
    **/
    function _buildQueryOrderBy()
    {
        //global $mainframe, $option;
        //Migration modification
        $option = JRequest::getCmd('option');
        $mainframe = JFactory::getApplication();

        // Array of allowable order fields
        $orders = array('a.username','b.name','code','send','validated');
        
        // Get the order field and direction, default ordering is
        // send, default direction is descending
		$filter_order = $mainframe->getUserStateFromRequest("'$option'.filter_order", 'filter_order', 'send');
        $filter_order_Dir = strtoupper($mainframe->getUserStateFromRequest("'$option'.filter_order_Dir", 'filter_order_Dir', 'DESC'));
        
        // Validate order direction
        if ($filter_order_Dir != 'ASC' && $filter_order_Dir != 'DESC')
        {
            $filter_order_Dir = 'ASC';
        }
        
        // If order column is unknown, choose default
        if (!in_array($filter_order, $orders))
        {
            $filter_order = 'send';
        }
        $orderby = ' ORDER BY '.$filter_order.' '.$filter_order_Dir;
        
        if ($filter_order != 'send')
        {
            $orderby .= ' , send ';
        }
        return $orderby;
    }
    /**
     * Get data from the model
    **/
    function getData()
    {
        if (empty($this->_data))
        {
            $query = $this->_buildQuery();
            $limitstart = $this->getState('limitstart');
            $limit = $this->getState('limit');
            $this->_data = $this->_getList($query,$limitstart, $limit);
        }
        return $this->_data;
    }
    
    /**
     * Get paging element from the model
    **/
    function getPagination()
    {
        if (empty($this->_pagination))
        {
            // Import pagination library
            jimport('joomla.html.pagination');   
            // Prepare pagination values
            $total = $this->getTotal();
            $limitstart = $this->getState('limitstart');
            $limit = $this->getState('limit');
            // Create the pagination object
            $this->_pagination = new JPagination($total, $limitstart, $limit);
        }
        return $this->_pagination;
    }
    
    /**
     * Get total amount of elements to show (for the paging)
    **/
    function getTotal()
    {
        if (empty($this->total))
        {
            $query = $this->_buildQuery();
            $this->_total = $this->_getListCount($query);
        }
        return $this->_total;
    }
    
	/**
	 * Method to validate record(s)
	 *
	 * @access    public
	 * @return    boolean    True on success
	**/
	function validate()
	{
		return $this->_setValidated(2);
	}
	
	/**
	 * Method to unvalidate record(s)
	 *
	 * @access    public
	 * @return    boolean    True on success
	**/
	function unvalidate()
	{
		return $this->_setValidated(0);
	}
	
	/**
	 * Method to set the validated field of record(s)
	 *
	 * @access     private
	 * @return     boolean    True on success
	**/
	function _setValidated($value)
	{
		$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
		$row =& $this->getTable();
	 
		foreach($cids as $cid) {
			// Bind the validated field and username to the mobilevalidate table
			$data = array('validated' => $value, 'username' => $cid);
			if (!$row->bind($data)) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
			
			// Make sure the record is valid
			if (!$row->check()) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
			
			// Store the mobilevalidate table to the database
			if (!$row->store()) {
				$this->setError( $this->_db->getErrorMsg() );
				return false;
			}
		}
	 
		return true;
	}
}
?>

查看:

<?php

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

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

class mobileactivationmobilevalidateViewmobilevalidate extends JViewLegacy
{
   
    function display($tpl = null)
    {   

        //global $mainframe,;

        $mainframe = JFactory::getApplication();
        $option = JRequest::getCmd('option');
        
        JToolBarHelper::title(JText::_('MV_TITLE'), 'generic.png');
        JToolBarHelper::custom( 'validate', 'apply.png', 'apply_f2.png', JText::_('VERIFY') );
        JToolBarHelper::custom( 'unvalidate', 'cancel.png', 'cancel_f2.png', JText::_('UNVERIFY') );
        
        
        // Prepare list array
        $lists = array();

        // Get the user state
        $filter_order = $mainframe->getUserStateFromRequest("'$option'.filter_order",'filter_order', 'send');
        $filter_order_Dir = $mainframe->getUserStateFromRequest("'$option'.filter_order_Dir",'filter_order_Dir', 'ASC');
        $filter_validated = $mainframe->getUserStateFromRequest("'$option'.filter_validated",'filter_validated');
        $filter_search = $mainframe->getUserStateFromRequest("'$option'.filter_search",'filter_search');
        $validated = array(
                        array('val'=>'-1','text'=> JText::_('CHOOSE_VERIFICATION')),
                        array('val'=>'0','text'=> JText::_('STATUS_0')),
                        array('val'=>'1','text'=> JText::_('STATUS_1')),
                        array('val'=> '2','text'=> JText::_('STATUS_2')));
						
        // Build the list array for use in the layout
        $lists['validated_value'] = $filter_validated;
        $lists['order'] = $filter_order;
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['validated'] = JHTML::_('select.genericList',$validated, 'filter_validated', 'class="inputbox" size="1" onchange="document.adminForm.submit()"', 'val','text', $filter_validated);
        $lists['search'] = $filter_search;
        
        // Get data and pagination from the model
        $model =$this->getModel('mobilevalidate');
        $data =$model->getData();
        $pagination =$this->get('Pagination');

        // Assign references for the layout to use
        $this->assignRef('lists', $lists);
        $this->assignRef('items', $data);
        $this->assignRef('page', $pagination);
        
        parent::display($tpl);
    }
}


?>

模板:

<?php
defined('_JEXEC') or die ('Restricted access');
?>

<form action="index.php?option=com_mobileactivation" method="post" name="adminForm">
<table>
  <tr>
    <td width="100%" nowrap="nowrap">
        <?php echo JText::_('Filter'); ?>:
        <input type="text" name="filter_search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="this.form.submit();" />
        <button onclick="this.form.submit();">
          <?php echo JText::_('Search'); ?>
        </button>
        <button onclick="document.adminForm.
                filter_search.value='';this.form.submit();">
          <?php echo JText::_('Reset'); ?>
        </button>
      <?php echo $this->lists['validated']; ?>
    </td>
  </tr>
</table>
<div id="editcell">
    <table class="adminlist">
        <thead>
            <tr>
                <th width="5">
                <input type="checkbox" name="toggle"
                    value="" onclick="checkAll(<?php echo
                    count($this->items); ?>);" />
                </th>
                <th width="20%"><?php echo JHTML::_('grid.sort', JText::_('PHONE_NUMBER'), 'a.username', $this->lists['order_Dir'], $this->lists['order'] );?></th>
				<th width="20%"><?php echo JHTML::_('grid.sort', JText::_('NAME'), 'b.name', $this->lists['order_Dir'], $this->lists['order'] );?></th>
                <th width="20%"><?php echo JHTML::_('grid.sort', JText::_('CODE'), 'code', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                <th width="20%"><?php echo JHTML::_('grid.sort', JText::_('SENT'), 'send', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                <th><?php echo JHTML::_('grid.sort', JText::_('VERIFIED'), 'validated', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
            </tr>
        </thead>
        <?php
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)	{
            $row = &$this->items[$i];
            $checked = JHTML::_('grid.id', $i, $row->username );
        ?>
            <tr class="<?php echo "row" . $k; ?>">
                <td><?php echo $checked; ?></td>
                <td><?php echo $row->username; ?></td>
				<td><?php echo $row->name; ?></td>
                <td><?php echo $row->code; ?></td>
                <td><?php echo $row->send; ?></td>
                <td><?php echo JText::_('STATUS_'.$row->validated); ?></td>
            </tr>
        <?php
            $k = 1 - $k;
        }
        ?>
    <tfoot>
        <tr>
            <td colspan="6"><?php echo $this->page->getListFooter(); ?></td>
        </tr>
    </tfoot>
    </table>
</div>
<input type="hidden" name="option" value="com_mobileactivation" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="mobilevalidate" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>

0 个答案:

没有答案