// Define inline keyboard pagination.
$ikp = new InlineKeyboardPagination($items, $command);
$ikp->setMaxButtons(7, true); // Second parameter set to always show 7 buttons if possible.
$ikp->setRangeOffset(1); //optional: if you change offsets of selected page, you can use this method. e.g if selected page is 6 and Range offset set as 1, you will have 5 & 7 in pagination
$ikp->setLabels($labels);
/*
*optional: But recommended. if you want that max_page will set according to labels you defined,
* please call this method. if you remove $label elements and then call this method, max_page will be defined according to labels
*/
$ikp->setMaxButtonsBasedOnLabels();
$ikp->setCallbackDataFormat($callback_data_format);
// Get pagination.
$pagination = $ikp->getPagination($selected_page);
// or, in 2 steps.
$ikp->setSelectedPage($selected_page);
$pagination = $ikp->getPagination();
// Use it in your request.
if (!empty($pagination['keyboard'])) {
//$pagination['keyboard'][0]['callback_data']; // command=testCommand&oldPage=10&newPage=1
//$pagination['keyboard'][1]['callback_data']; // command=testCommand&oldPage=10&newPage=7
...
$data['reply_markup' => [
'inline_keyboard' => [
$pagination['keyboard'],
],
];
...
}
// e.g. Callback data.
$callback_data = 'command=testCommand&oldPage=10&newPage=1';
$params = InlineKeyboardPagination::getParametersFromCallbackData($callback_data);
//$params = [
// 'command' => 'testCommand',
// 'oldPage' => '10',
// 'newPage' => '1',
//];
// or, just use PHP directly if you like. (literally what the helper does!)
parse_str($callback_data, $params);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.