What we are first doing in the Breeds model class is, we are calling the parent populate state method that resides in the JModelList and passing it the information about pagination, which is the maximum limit of the results to be displayed on a page and secondly the starting point of the list or you can say that from which point the results list should start. At the start, we have initialized the $app variable for holding the Joomla application object. This application object is the same thing that pulls and puts together the components, modules, plugins and templates to make our complete web page. We get this object through getApplication method, belonging to JFactory method.
If you have so many records in a specific database table and are populating the results in the list view, then if you are on page 1 of the list, the “limitstart” value would be 0 and if you have selected to display 5 results per page and you are on page 2, the limitstart value will become 5. So you can say that $limitstart specifies which item is the first to be displayed on the current page. So, in our populatestate method, the variables, $limit and $limitstart are getting these two values respectively through “getUserStateFromRequest” method.
This feature enables Joomla to record the state or value of a particular variable, it is getting from request and to handle this, there is a state of the art method, called, “getUserStateFromRequest“. This behaves like a very useful method belonging to JApplication class and comes with a number of arguments. Starting from the $limit property on line 21, the first argument passed to the method is, the path to the value in the state data. It is mentioned here as , “global.list.limit” because this value is not component specific and will globally remain the same in Joomla. the second argument is the input request name from which the value will be updated. The last argument, $app->get(‘list_limit’) provides the default value for pagination limit and it picks this from main configuration file. If you want to override all of this stuff, you can simply assign the limit variable, an integer value like, $limit = 20;. The arguments for the $limitstart are also self explanatory, we are getting the values from limitstart variable and passing 0 as a default offset value.
You can easily change the list limit from backend, by logging in to backend as super user and then going to System –> Global Configuration –> Site Settings and then set the Default List Limit.
So, on the basis of this, you can say that through “populateState” method, we can easily get the information from the request in the model. The JModelList class also provides several other request variables that make us to interact with lists more easily such as column ordering and direction, listing page length etc.
$this->pagination = $this->get('Pagination');
Add the code mentioned on line 4 to the view.html.php file at the same position as shown in the above code. This line of code will fetch the pagination object from model and assign it so that it can vbe used in the template file.
In the breeds list default.php file, we are adding the above mentioned code after the closing tbody section of table. We are closing the pagination code in the tfoot section and on line 8, we have added some php code to calculate number of columns it has to calculate for proper rendering of tfoot section according to the table body and header on the basis of setting the column span. After that, there is a php code for rendering paginations buttons by calling getListFooter() method through pagination object.
I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.
Enjoy best web development services at an affordable price. Looking forward to build a good relationship and serve you better...
My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.