Joomla分页不适用于joomla 3.0

时间:2014-03-27 11:28:33

标签: php pagination joomla3.0 joomla-component

我已经为我自己的组件创建了joomla分页,并且它对joomla 2.5工作正常,我使用相同的joomla 3.0数据显示,并且分页也正确显示但问题是当我点击任何分页没有。对于下一页或上一页,其不工作表格仍保留在同一页面上。

以下是我用于创建分页的代码。

 model.php


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

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


     class eventsModelEvents extends JModelLegacy {

     var $_total = null;
     var $_pagination = null;
     function __construct()
     {
            parent::__construct();

            $mainframe = JFactory::getApplication();

            // Get pagination request variables
            $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
             $limitstart = JRequest::getVar('limitstart', 0, '', 'int');

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

             $this->setState('limit', $limit);
             $this->setState('limitstart', $limitstart);
  }
   function getPagination()
  {
        // Load the content if it doesn't already exist
        if (empty($this->_pagination)) {
            jimport('joomla.html.pagination');
            $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
        }
        return $this->_pagination;
  }
   function getTotal()
  {
        // Load the content if it doesn't already exist
        if (empty($this->_total)) {
            $query = $this->_buildQuery();
            $this->_total = $this->_getListCount($query);       
        }
        return $this->_total;
  }
  function getData() 
  {
        // if data hasn't already been obtained, load it
        if (empty($this->_data)) {
            $query = $this->_buildQuery();
            $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));    
        }
        return $this->_data;
  }
    function _buildQuery()
        {
                // Create a new query object.           
                $db = JFactory::getDBO();
                $query = $db->getQuery(true);
                // Select some fields
                $query->select('*');
                // From the hello table
                $query->from('#__events');
                $query->order('date DESC');
                return $query;
        }
    function getEvents(){
             $db = $this->getDBO();

             $db->setQuery('SELECT * from #__events');
             $events = $db->loadObjectList();

             if ($events === null)
                    JError::raiseError(500, 'Error reading db');

             return $events;
       }
       function getEvent($id){
             $query = ' SELECT * FROM #__events '.
                            ' WHERE id = '.$id;
             $db = $this->getDBO();
             $db->setQuery($query);
             $event = $db->loadObject();          

             if ($event === null)
                    JError::raiseError(500, 'Event with ID: '.$id.' not found.');
             else
                    return $event;          
       }
        function saveEvent($event){

        $db = $this->getDBO();
        $uploaded_path = JPATH_COMPONENT. "/images/";
        if($_FILES["event_image"]["tmp_name"]){
                 if ($_FILES["event_image"]["error"] > 0){
                    return $_FILES["event_image"]["error"] . "<br>";
                } else {
                    move_uploaded_file($_FILES["event_image"]["tmp_name"],$uploaded_path . $_FILES["event_image"]["name"]);                 
                    $event['event_image'] = $_FILES["event_image"]["name"];
                }   

        } else {
            $event['event_image'] = $event['event_stored_image'];

        }


         $event['event_date'] = date('Y-m-d H:i:s', strtotime($event['event_date']));
        foreach($event as $key => $value){
            $event[$key] = mysql_real_escape_string($value);
        }

        if(($event['event_name'] != NULL ) && ($event['event_image'] != NULL)  && ($event['event_date'] != NULL) && ($event['event_description'] != NULL)){

            if(isset($event['event_id'])){
            $query = "UPDATE #__events SET name = '".$event['event_name']."',status =  '".$event['event_status']."',image = '".$event['event_image']."',date =  '".$event['event_date']."',description = '".$event['event_description']."',reservation = '".$event['event_reservation']."' WHERE id =" . $event['event_id']; 
        } else {
            $query = "INSERT INTO #__events (name,status,image,date,description,reservation) VALUES ('".$event['event_name']."','".$event['event_status']."','".$event['event_image']."','".$event['event_date']."','".$event['event_description']."', '".$event['event_reservation']."')"; 
        }

             $db->setQuery($query); 
             if (!$db->query()){
                        $errorMessage = $this->getDBO()->getErrorMsg();
                        JError::raiseError(500, 'Error inserting event: '.$errorMessage);  
               }    
        } else {

             return "Please Fill All fields.";
        }

     }

     function deleteEvents($arrayIDs)
         {
                   $query = "DELETE FROM #__events WHERE id IN (".implode(',', $arrayIDs).")";
                   $db = $this->getDBO();
                   $db->setQuery($query);
                   if (!$db->query()){
                            $errorMessage = $this->getDBO()->getErrorMsg();
                            JError::raiseError(500, 'Error deleting events: '.$errorMessage);  
                   }                  
         }
     function publishEvents($arrayIDs)
         {
                  $query = "UPDATE #__events SET status = '1'  WHERE id IN (".implode(',', $arrayIDs).")"; 
                   $db = $this->getDBO();
                   $db->setQuery($query);
                   if (!$db->query()){
                            $errorMessage = $this->getDBO()->getErrorMsg();
                            JError::raiseError(500, 'Error publishing events: '.$errorMessage);  
                   }                  
         }
     function unpublishEvents($arrayIDs)
         {
                  $query = "UPDATE #__events SET status = '0'  WHERE id IN (".implode(',', $arrayIDs).")"; 
                   $db = $this->getDBO();
                   $db->setQuery($query);
                   if (!$db->query()){
                            $errorMessage = $this->getDBO()->getErrorMsg();
                            JError::raiseError(500, 'Error publishing events: '.$errorMessage);  
                   }                  
         }
}

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

class eventsViewEvents extends JViewLegacy {
    protected $categories;
    protected $items;
    protected $pagination;
    protected $state;
    function display($tpl = null) 

    {



        $this->categories   = $this->get('CategoryOrders');
        $this->state        = $this->get('State');
        $this->addToolBar();
         // Get data from the model
        $events = $this->get('Data');   
        $pagination =$this->get('Pagination');
        // push data into the template
        $this->events = $events;    
        $this->assignRef('pagination', $pagination);
        parent::display($tpl);

    }
    function add($tpl = null){
        $this->addToolBar();


        parent::display($tpl);

    }

        protected function addToolbar()
    {
        require_once JPATH_COMPONENT . '/helpers/events.php';

        $canDo = EventsHelper::getActions($this->state->get('filter.category_id'));
        $user = JFactory::getUser();
        JToolBarHelper::title('Event Manager', 'generic.png');
        JToolBarHelper::addNew('add');
        if (count($user->getAuthorisedCategories('com_events', 'core.create')) > 0)
        {
            //JToolBarHelper::addNew('add');
        }

        if (($canDo->get('core.edit')))
        {
            JToolBarHelper::editList('edit');
        }

        if ($canDo->get('core.edit.state'))
        {
            if ($this->state->get('filter.state') != 2)
            {
                JToolBarHelper::divider();
                JToolBarHelper::publish('publish', 'JTOOLBAR_PUBLISH', true);
                JToolBarHelper::unpublish('unpublish',  'JTOOLBAR_UNPUBLISH', true);
            }


        }



        if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete'))
        {
            JToolBarHelper::deleteList('', 'remove', 'JTOOLBAR_EMPTY_TRASH');
            JToolBarHelper::divider();
        }
        elseif ($canDo->get('core.edit.state'))
        {
            JToolBarHelper::trash('remove');
            JToolBarHelper::divider();
        }
    }

    function displayEdit($eventId,$tpl = NULL)
    {                            

       JToolBarHelper::title('Event'.': [<small>Edit</small>]');
       JToolBarHelper::save();
       JToolBarHelper::cancel();  

       $model = $this->getModel();
       $event = $model->getEvent($eventId);
       $this->event = $event;

       parent::display($tpl);
    }
     function displayAdd($tpl = NULL){
             JToolBarHelper::title('Event'.': [<small>Add</small>]');
             JToolBarHelper::save();
             JToolBarHelper::cancel();  


             parent::display($tpl);
    }

    }

     default.php

     <td colspan="9"><?php echo $this->pagination->getListFooter(); ?></td>

可以帮助我解决错误或缺少什么

2 个答案:

答案 0 :(得分:1)

这可能是因为所需的Javascript框架不可用。为了确保在这种情况下,您可以检查您的JavaScript控制台。

如果是这种情况,请在您的视图中延伸JViewLegacy,在行之前:

$this->pagination = $this->get('Pagination');

插入以下行:

JHtml::_('behavior.framework');

另外,请确保您的模板没有删除所需的框架。

unset($doc->_scripts[JURI::root(true) . '/media/system/js/core.js']);

如果您在模板index.php

中看到此行,请注释掉该行

希望这会有所帮助:)

答案 1 :(得分:0)

扩展类JModelList而不是JModelLegacy,这应该很抱歉。