简体   繁体   English

Joomla分页不适用于joomla 3.0

[英]Joomla pagination is not working for joomla 3.0

I have created joomla pagination for my own component and its working fine for joomla 2.5 and i have use same for joomla 3.0 the data is displaying and also the pagination is also displaying correctly but the issue is when i click on any pagination no. 我已经为自己的组件创建了joomla分页,并且它对joomla 2.5正常工作,并且我对joomla 3.0使用了它,数据正在显示,并且分页也正确显示,但是问题是当我单击任何分页时。 for going next or prev page its not working form remains on same page. 进入下一页或上一页时,其无效表格仍保留在同一页面上。

Here is code i have used for creating pagination. 这是我用于创建分页的代码。

 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>

Can any help me what is wrong or what i am missing 有什么可以帮助我什么地方是错的或我所缺少的

This might be because the required Javascript frameworks aren't available. 这可能是因为所需的Javascript框架不可用。 To ensure if this is the case, you can check your javascript console. 为确保确实如此,您可以检查JavaScript控制台。

If that is the case, in your view extending JViewLegacy , before the line: 如果是这种情况,在您的视图中,在该行之前扩展JViewLegacy

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

Insert below line: 在下面的行中插入:

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

Also, make sure your template is not removing the required frameworks. 另外,请确保您的模板没有删除所需的框架。

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

Comment out this line if you see it in your template index.php 如果在模板index.php看到此行,请注释掉该行

Hope this helps :) 希望这可以帮助 :)

扩展类JModelList而不是JModelLegacy,应该对此感到抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM