0

我想在 CodeIgniter 中创建自己的助手,但我不知道出了什么问题。我将复制我的帮助文件,并在我的另一个文件中初始化此帮助文件并尝试回显,但没有任何显示。

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

     if (!function_exists('pagination'))

{

    function prikazi($per_page, $page, $url, $total)
    {
        $CI =& get_instance();
           $adjacents = "2";


    $page = ($page == 0 ? 1 : $page); 
    $start = ($page - 1) * $per_page;                              

    $prev = $page - 1;                         
    $next = $page + 1;
    $lastpage = ceil($total/$per_page);
    $lpm1 = $lastpage - 1;

    $pagination = "";
    if($lastpage > 1)
    {  
       $pagination .= "<ul class='pagination'>";
           $pagination .= "<li class='details'>Page $page of $lastpage</li>";
        if ($lastpage < 7 + ($adjacents * 2))
        {  
            for ($counter = 1; $counter <= $lastpage; $counter++)
            {
                if ($counter == $page)
                    $pagination.= "<li><a class='current'>$counter</a></li>";
                else
                    $pagination.= "<li><a href='{$url}$counter'>$counter</a></li>";                   
            }
        }
        elseif($lastpage > 5 + ($adjacents * 2))
        {
            if($page < 1 + ($adjacents * 2))    
            {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>$counter</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}$counter'>$counter</a></li>";                   
                }
                $pagination.= "<li class='dot'>...</li>";
                $pagination.= "<li><a href='{$url}$lpm1'>$lpm1</a></li>";
                $pagination.= "<li><a href='{$url}$lastpage'>$lastpage</a></li>";     
            }
            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
            {
                $pagination.= "<li><a href='{$url}1'>1</a></li>";
                $pagination.= "<li><a href='{$url}2'>2</a></li>";
                $pagination.= "<li class='dot'>...</li>";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>$counter</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}$counter'>$counter</a></li>";                   
                }
                $pagination.= "<li class='dot'>..</li>";
                $pagination.= "<li><a href='{$url}$lpm1'>$lpm1</a></li>";
                $pagination.= "<li><a href='{$url}$lastpage'>$lastpage</a></li>";     
            }
            else
            {
                $pagination.= "<li><a href='{$url}1'>1</a></li>";
                $pagination.= "<li><a href='{$url}2'>2</a></li>";
                $pagination.= "<li class='dot'>..</li>";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
                {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>$counter</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}$counter'>$counter</a></li>";                   
                }
            }
        }

        if ($page < $counter - 1){
            $pagination.= "<li><a href='{$url}$next'>Next</a></li>";
           // $pagination.= "<li><a href='{$url}$lastpage'>Last</a></li>";
        }else{
            //$pagination.= "<li><a class='current'>Next</a></li>";
           // $pagination.= "<li><a class='current'>Last</a></li>";
        }
        $pagination.= "</ul>\n";     
    }          
        return $pagination;
    }
}

在我的另一个文件中,我尝试像这样回显:

  $this->load->helper('pagination');
    echo prikazi($bypage,$page,$link,$total); 
4

1 回答 1

0

When you look at

$lastpage = ceil($total/$per_page);
$lpm1 = $lastpage - 1;

$pagination = "";
if($lastpage > 1)
{  
...
} else
return $pagination;

it probably boils down that $lastpage is 0, so an empty string is returned.

You might want to have a look at

 if (!function_exists('pagination'))

{

function prikazi($per_page, $page, $url, $total)
{

too because the function names don't match

于 2013-01-09T15:46:48.023 回答