my first go at pagination in the control panel so I’m following : https://docs.expressionengine.com/latest/development/legacy/libraries/table.html
from my _datasource function I’m returning the following:
return array(
'rows' => array_slice($this->data["log_results"], $offset, 1),
'pagination' => array(
'per_page' => 1,
'total_rows' => count($this->data["log_results"]),
),
);
In which case I get a fatal error :
`
Fatal error: __clone method called on non-object in /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/legacy/libraries/Table.php on line 1043
However if I only return:
return array(
'rows' => array_slice($this->data["log_results"], $offset, 1)
);
I see my one row properly, but of course I get a message that pagination_html is an undefined index in my view. which is using:
$data = ee()->table->datasource('_datasource');
echo $data['table_html'];
echo $data['pagination_html'];
am I missing something?
==== Here’s the source for those sections ===
//inside my mcp class
public function _datasource($state,$params) {
$offset = $state['offset'];
$log_results = ee()->db->get("dwg_scma_transaction-log");
if($log_results ->num_rows > 0){
foreach ($log_results->result_array() as $row){
$id = $row['log_id'];
$row["view_details"]= '<a href="/system/index.php?/cp/addons/settings/dwg_scma/details/.$rowlog_id">.'"]View Details</a>';
$this->data["log_results"][$id]=$row;
}
}else{
$this->data["log_results"][0] = "No Transaction's Found.";
}
return array(
'rows' => array_slice($this->data["log_results"], $offset, 1),
'pagination' => array(
'per_page' => 1,
'total_rows' => count($this->data["log_results"]),
),
);
}
It won’t let me post the following in code tags for some reason so here you go in plain text:
//index.php view <h1>All Transactions</h1> Generate CSV ;” class=”button”]Print Transactions <div> <?php ee()->load->library(‘table’); ee()->table->set_columns(array( ‘log_id’=>array(‘header’,’Log ID#’), ‘last_name’=>array(‘header’,’Last Name’), ‘member_id’=>array(‘header’,’Member ID’), ‘creation_date’=>array(‘header’,’Date’), ‘transaction_id’=>array(‘header’,’Transaction ID’), ‘payment_amount’=>array(‘header’,’Amount’), ‘response_code’=>array(‘header’,’Response Codes’), ‘view_details’=>array(‘header’,’View Details’) )); $default_state = array(‘sort’ => array(‘log_id’ => ‘asc’)); $data = ee()->table->datasource(‘_datasource’,$default_state); echo $data[‘table_html’]; echo $data[‘pagination_html’]; ?> </div>
… and the fatal error
Fatal error: __clone method called on non-object in /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/legacy/libraries/Table.php on line 1043
Call Stack:
0.0009 246240 1. {main}() /home/dubose/sandbox/dev_south_carolina_medical_association/system/index.php:0
0.0021 267664 2. require_once('/home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Boot/boot.php') /home/dubose/sandbox/dev_south_carolina_medical_association/system/index.php:148
0.0338 1663128 3. EllisLab\ExpressionEngine\Core\Core->run() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Boot/boot.php:151
0.0527 2518232 4. EllisLab\ExpressionEngine\Core\Core->runController() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Core/Core.php:94
0.3544 15681976 5. call_user_func_array() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Core/Core.php:189
0.3544 15682312 6. EllisLab\ExpressionEngine\Controller\Addons\Addons->settings() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Core/Core.php:189
0.3580 15810888 7. EllisLab\ExpressionEngine\Controller\Addons\Addons->getModuleSettings() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Controller/Addons/Addons.php:893
0.3742 17344032 8. call_user_func_array() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Controller/Addons/Addons.php:1629
0.3742 17344200 9. Dwg_scma_mcp->index() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Controller/Addons/Addons.php:1629
0.3742 17344528 10. EllisLab\ExpressionEngine\Service\View\View->render() /home/dubose/sandbox/dev_south_carolina_medical_association/system/user/addons/dwg_scma/mcp.dwg_scma.php:21
0.3742 17345432 11. EllisLab\ExpressionEngine\Service\View\View->parse() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Service/View/View.php:110
0.3747 17381016 12. include('/home/dubose/sandbox/dev_south_carolina_medical_association/system/user/addons/dwg_scma/views/index.php') /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/EllisLab/ExpressionEngine/Service/View/View.php:145
0.3760 17543800 13. EE_Table->datasource() /home/dubose/sandbox/dev_south_carolina_medical_association/system/user/addons/dwg_scma/views/index.php:21
0.3776 17931784 14. EE_Table->_create_pagination() /home/dubose/sandbox/dev_south_carolina_medical_association/system/ee/legacy/libraries/Table.php:204
Hi Andy. The old table library isn’t really used anymore, I don’t it works. I’d recommend using the new Table service coupled with the Pagination service. You should fine some real examples of both in action in the control panel.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.