调用未定义的函数setSurroundCount()CodeIgniter 4



我试图在视图中实现分页,但当我调用setSurroundCount函数时,它会给我一个错误"调用未定义的方法CodeIgniter\Pager\Pager:ConfusedetSurroundCount(("有人知道为什么吗?

这是我的控制器:

function index($limit=100) {
$model = new AppModelsTransactionModel();
$data = [
'title' => "Transactions",
'transactionsHTMLTable' => $this->formatTransactionsAsHTMLTable($model->paginate($limit)),
'pager' => $model->pager
];
echo view('top', $data);
echo view('transactions', $data);
echo view('bottom');
} 

以下是我的观点;

<h3>Transactions</h3>
<?php
echo $transactionsHTMLTable;
// echo $pager->links();
$pager->setSurroundCount(2);
?>
<nav aria-label="Page navigation">
<ul class="pagination">
<?php if ($pager->hasPrevious()) : ?>
<li>
<a href="<?= $pager->getFirst() ?>" aria-label="First">
<span aria-hidden="true">First</span>
</a>
</li>
<li>
<a href="<?= $pager->getPrevious() ?>" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<?php endif ?>
<?php foreach ($pager->links() as $link) : ?>
<li <?= $link['active'] ? 'class="active"' : '' ?>>
<a href="<?= $link['uri'] ?>">
<?= $link['title'] ?>
</a>
</li>
<?php endforeach ?>
<?php if ($pager->hasNext()) : ?>
<li>
<a href="<?= $pager->getNext() ?>" aria-label="Previous">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
<li>
<a href="<?= $pager->getLast() ?>" aria-label="Last">
<span aria-hidden="true">Last</span>
</a>
</li>
<?php endif ?>
</ul>
</nav> 

以下是函数formatTransactionsAsHTMLTable((:

function formatTransactionsAsHTMLTable($transactions) {
$htmlTable = array();
$table = new CodeIgniterViewTable();
$template = [
'table_open' => '<table class="table table-striped table-hover table-sm small">'
];
$table->setTemplate($template);
$table->setHeading('ID', 'Date', 'Subscription ID', 'Duration', 'Price', 'Proceed', 'Device', 'Country', 'Subscriber ID');
foreach ($transactions as $key => $transaction) {
$table->addRow($transaction['id'], $transaction['date'], $transaction['subscriptionId'], $transaction['duration'], $transaction['price'] . " " . $transaction['currency'], $transaction['proceed'] . " " . $transaction['proceedCurrency'], $transaction['device'], $transaction['country'], $transaction['subscriberId']);
}
return $table->generate();
}

我从Codeigniter 4文档中获取了所有内容。

如果我回显$pager->links((,它就工作了。所以$pager在这里,但是函数setSurroundCount getFirst、getNext。。。不起作用。有人能帮我吗?

您需要按照手册中的子标题来定制链接。在app/Views中创建一个文件夹(Pagers(,然后在其中创建一个视图文件。它将是Pagers/name_of_view_file.php。

然后,您需要编辑app/Pager.php来使用您的视图文件。

相关内容

  • 没有找到相关文章

最新更新