'Codeigniter - Pagination undefined function
i have a function to show data from controller like this :
public function leaderboards()
{
if($this->ion_auth->logged_in()){
$leaderboard = $this->FrontModel->getLeaderboard();
$dataLeaderboard = ''; $no = 1;
foreach ($leaderboard as $row) {
$dataLeaderboard .='
<tr class="calculate-price-wrapper post">
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$no.'.</strong></div>
</td>
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$row['fname'].'</strong></div>
</td>
<td >
<div class="mv-font-secondary mv-f-14"><strong>'.$this->replace_character($row['email']).'</strong></div>
</td>
<td>
<div class="mv-font-secondary mv-f-14"><strong>'.$row['total_point'].'</strong></div>
</td>
</tr>
';
$no++;
}
/* pagination */
$config = array();
$config["base_url"] = base_url(). "leaderboards";
$config["total_rows"] = count($dataLeaderboard);
$config["per_page"] = 20;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page);
$data['pagination'] = $this->pagination->create_links();
/* data template - header footer */
$template['menuActive'] = 'leaderboard';
$template['menuLoggedIn'] = $this->menuLoggedIn;
$this->load->view('front-end/template/header', $template);
$this->load->view('front-end/leaderboard', $data);
$this->load->view('front-end/template/footer', $template);
}else{
redirect('auth', 'refresh');
}
}
And here is the my view :
<!-- .main-breadcrumb-->
<section class="mv-main-body cart-main mv-bg-gray mv-wrap">
<div class="container">
<div class="latest-blog-title mv-title-style-3 no-text-behind" style="padding-bottom:30px;">
<div class="title-3-text"><span class="main">LEADERBOARD</span></div>
<div class="title-3-line"></div>
</div>
<div class="cart-inner">
<div class="cart-block block-cart-table mv-bg-white mv-box-shadow-gray-1 mv-mb-50">
<div class="mv-table-responsive">
<table class="mv-table-style-2">
<thead>
<tr>
<th style="width:15%;">Pos.</th>
<th style="width:30%;">Name</th>
<th style="width:30%;">Email</th>
<th style="width:20%;">Point</th>
</tr>
</thead>
<tbody>
<?=$dataLeaderboard?>
</tbody>
</table>
<div class="mv-pagination-wrapper mv-mt-25 mv-mb-25">
<div class="mv-pagination-style-1 has-count-post">
<?php echo $pagination; ?>
</div>
<!-- .mv-pagination-style-1-->
</div>
</div>
</div>
</div>
</div>
</section>
but it ended up having an error like this :
Fatal error: Call to undefined function <tr class="calculate-price-wrapper post"> <td> <div class="mv-font-secondary mv-f-14"><strong>1.</strong></div> </td> <td> <div class="mv-font-secondary mv-f-14"><strong>Test Name</strong></div> </td> <td > <div class="mv-font-secondary mv-f-14"><strong>te*s*n*ame*g*ai*.c*m</strong></div> </td> <td> <div class="mv-font-secondary mv-f-14"><strong>55</strong></div> </td> </tr> <tr class="calculate-price-wrapper post"> <td> <div class="mv-font-secondary mv-f-14"><strong>2.</strong></div> </td> in C:\xampp5.6\htdocs\motogp2022\application\controllers\front-end\MainController.php on line 703
A PHP Error was encountered Severity: Error
Message: Call to undefined function
- Test Name tesnamegai.c*m 55
- Filename: front-end/MainController.php
Line Number: 703
Backtrace:
And the line that cause the error was this line in my controller :
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page); //Line 703
anyone know solution for this? anyhelp is really appreciated, thank you!.
Solution 1:[1]
In this line:
$data['dataLeaderboard'] = $dataLeaderboard($config["per_page"], $page);
You are using $dataLeaderboard as a function. You are setting it as a string of HTML, hence you're getting that the HTML does not exist as a function.
Not knowing your full code, but what I think you need to do is:
- Not create the leaderboard data as a single string, but rather as an array of HTML (so not
$dataLeaderboard .= ...but rather$dataLeaderboard[] = .... - Then do
$data['dataLeaderboard'] = $dataLeaderboard. For brevity, you can in your loop directly set it into an array$data['dataLeaderboard']. You will not set it as$dataLeaderboard(...). The round bracket around the variable means you're trying to use the variable as a function, which it is not. - For full implementation of the pagination library in CI, check this manual page: https://codeigniter.com/userguide3/libraries/pagination.html. There is a specific set configuration options and code lines that must be present, and your pagination library must be loaded, of course.
There might be more to do after that, but start there.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
