[TYPO3-english] pagebrowse

Victor Livakovsky v-tyok at mail.ru
Fri May 4 15:46:51 CEST 2012


Hi, Robert.

> Well... really simple ... probably for an experienced EXT developer, but 
> not for a newbie. EG: where is one expected to put that code snippet of 
> getListGetPageBrowser?
> When I put it in my pi1-class, I get an error about some undefined class. 
> But pagebrowse is installed, and - if I understand the code correctly, I 
> do not have to include anymore classes at the top of my extention class, 
> right?

Okay...
Yes, you shouldn't include any other class.

Your pi-class should look like this:
class tx_myext_pi1 extends tslib_pibase {
    ...
}

Put inside that method (getListGetPageBrowser).
/**
     * Gets list of pages from 'pagebrowse' ext.
     *
     * @return string Pagebrowser's content.
     * @param int $numberOfPages Full number of pages.
     * @param string $pageVar Name of 'page' in piVars.
     */
    function getListGetPageBrowser($numberOfPages, $pageVar = 'page' ) {

        $conf = 
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_pagebrowse_pi1.'];

        $conf['pageParameterName'] = $this->prefixId . '|'. $pageVar;
        $conf['numberOfPages'] = $numberOfPages;
        $conf['disableCacheHash'] = 1;

        $cObj = t3lib_div::makeInstance('tslib_cObj');
        /* @var $cObj tslib_cObj */
        $cObj->start(array(), '');
        return $cObj->cObjGetSingle('USER_INT', $conf);
    }

In your main() method you may do this:
$recordsList = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($select, $from, 
$where, $groupBy, $orderBy, $limit);
$fullRecCount = count($recordsList );
$recordsList = array_slice($recordsList, $this->piVars['page'] * 
$this->conf['listView.']['limit'], $this->conf['listView.']['limit']);

First line selects records from db and puts them into array (you mey read 
more about db related TYPO3 functions by looking inside t3lib/t3lib_db.php 
class).
Second line finds quantity of all the records (if you didn’t set limit, 
obviously).
Third line gets that piece of records, that are requested by user, using 
pagebrowser. Current page number is stored in $this->piVars['page'], 
$this->conf['listView.']['limit'] takes amount of records per page from TS 
of your extension (you should, probably, know, how to set some TS options 
for extensions).

After that you may do the output:
foreach($announcementsList as $announcement) {
    // your code, that makes output of every record comes here
}

And finally you call your pagebrowser method:
$this-> content .= $this->getListGetPageBrowser(ceil($fullRecCount / 
$this->conf['listView.']['limit']));


And surely, best practice is to:
1) Play with extension kickstarter to see, what basic options are offered by 
TYPO3 API.
2) Read official API documents.
3) Look at other similar to yours extensions code to see, what methods do 
authors use and how do they use them.
4) Look at TYPO3 source code (Dmitry's book already gives directions, what 
to read).

Good luck! 



More information about the TYPO3-english mailing list