Did you still remember about the modification I created in my article which have the title How to Add Record Number Column on The List Page in Websites Created With PHPMaker 8.0.3? If so, you will see the difference between the modification I created in that article with the one I created in this current article. What is it?
Well, this time we are going to customize the PHPMaker codebase file instead of adding the code in all of ListOptions_Load and ListOptions_Rendered functions of the Server Events in order to insert the new column to display the record or row number in the List pages. By using this new technique, you don't have to add your code one by one to those two functions above in each table/view that you have already had.
In addition, by implementing this customization, you will learn how to insert your code into Server Events as the default code when you load PHPMaker for the very first time easily and quickly. This is very useful when you create a new project in the future, then your code will be used as the default code.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: This customization below has been handled by using MasinoFixedWidthSite extension. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
- Before we get started, please note that this customization has the limitation, since it needs defining Pagination first before executing the ListOptions_Rendered function. You have to enable at least the Paging section at top from PHP -> List/View Page Options (Global) of PHPMaker application. Make sure you don't miss this step!
-
Open your C:\Program Files\PHPMaker 9\languages\english.xml file, and find this code:
</global>
before that line, please insert the following code:
<phrase id="RecNo" value="Record Number"/>
Do the same way with your another .xml language file(s). For example, I am also using Indonesian, then I add my code into C:\Program Files\PHPMaker 9\languages\indonesian.xml file as following:
<phrase id="RecNo" value="Nomor Record"/>
-
Open your \Script\ewcfg.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Record Number on List Pages, by Masino Sinaga, June 1, 2012 define("MS_SHOW_RECORD_NUMBER_COLUMN_ON_LIST", TRUE, TRUE); // End of modification Record Number on List Pages, by Masino Sinaga, June 1, 2012 -
The next step, instead of adding one by one the code in each table of Server Events, we are gonna add the code via the phpcodebase.xml file, so it will save a lot of your time. Open your C:\Program Files\PHPMaker 9\src\phpcodebase.xml file, and find this code:
function ListOptions_Load() { // Example: //$opt = &$this->ListOptions->Add("new"); //$opt->Header = "xxx"; //$opt->OnLeft = TRUE; // Link on left //$opt->MoveTo(0); // Move to first column }then replace it with the following code:
function ListOptions_Load() { // Record Number Column, modified by Masino Sinaga, June 1, 2012 global $Language; if (MS_SHOW_RECORD_NUMBER_COLUMN_ON_LIST) { $opt =& $this->ListOptions->Add("RecNo"); // RecNo will refer to ListOptions_Rendered $opt->Header = $Language->Phrase("RecNo"); // the caption of column header $opt->CssStyle = "text-align: center;"; // make the content center align $opt->OnLeft = TRUE; // Link on left $opt->MoveTo(0); // Move to first column } // Record Number Column, modified by Masino Sinaga, June 1, 2012 } -
Still in that C:\Program Files\PHPMaker 9\src\phpcodebase.xml file, find again this code:
function ListOptions_Rendered() { // Example: //$this->ListOptions->Items["new"]->Body = "xxx"; }then replace it with the following code:
function ListOptions_Rendered() { /* // Record Number Column, modified by Masino Sinaga, June 1, 2012 if (MS_SHOW_RECORD_NUMBER_COLUMN_ON_LIST) { if (($this->Export == "") && ($this->CurrentAction != "gridedit") && ($this->CurrentAction != "gridadd") && ($this->Pager->CurrentPage > 1)) { $no = $this->RowCnt + ($this->Pager->CurrentPage-1)*$this->DisplayRecs; // normal list view, could be more than 1 page! } else { $no = $this->RowCnt; // export to print list view, only 1 page! } $this->ListOptions->Items["RecNo"]->Body = $no; } // Record Number Column, modified by Masino Sinaga, June 1, 2012 */ $this->ListOptions->Items["RecNo"]->Body = $this->RecCnt; } - Please note that since this customization will affect all List pages, then it might change in all existing code in your ListOptions_Load and ListOptions_Rendered functions. If you have already had code in those two functions, than you have to adjust them with the code above, as they will not replace the existing code you had before. Don't forget to backup your existing code in those two functions if you have ever written your code in them.
- Finally, re-generate your script files using PHPMaker application as always, and enjoy the results!
[/hidepost]
I implemented this after the “how-to-customize-pagination-style-in-websites-that-created-with-phpmaker-9-0-1” and I’m now getting the following error: Notice: Undefined property: cNumericPager::$CurrentPage in C:\xampp\htdocs\weekendsupport.org\weekends_list.php on line 3350
This is the line in that script: ($this->Pager->CurrentPage > 1)) {
which is located in the ListOptions_Rendered() function.
Since this customization in this current article is depending on cNumericPager class in the customization for pagination style, and if you want to show the record number column on the list, then you have to enable/display the pagination at the top section.
That error above will be occured if you are not displaying the pagination at the top section (for example only at the bottom section). So, in order to prevent that error, please enable the pagination at the top section (or both top and bottom section). This is the limitation of the customization in this article.
I’m using Top and bottom, but I also get the same results if I use top only.
I don’t have the problem if I use:
define(“MS_PAGINATION_STYLE”, 2, TRUE);
Only if I use a style of “1” will the problem show up.
One more thing I noticed. the record count per page always begins with 1 with a style of “1” as well. With a style of “2”. everything works as advertised.
Thanks for the feedback. Will investigate it and let you know the results.
Okay. Problem is solved now. I have just added a new customization step; number 14. Please re-apply step number 14 and 15 in the following article: How to Customize Pagination Style in Websites that Created With PHPMaker 9.0.1. It should fix the problem now.
It works as advertised. Perfectly. Thanks!
I’m displaying both top and bottom