Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9117115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:53+00:00 2026-06-17T04:49:53+00:00

i wanted to create my own helper in CodeIgniter, and i don’t know what’s

  • 0

i wanted to create my own helper in CodeIgniter, and i don’t know what’s wrong. I’ll copy my helper file , and in my other file i initalize this helper and try to echo and nothing shows up.

 <?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;
    }
}

And in my other file i try to echo like this :

  $this->load->helper('pagination');
    echo prikazi($bypage,$page,$link,$total); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:49:55+00:00Added an answer on June 17, 2026 at 4:49 am

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to create my own Python exception class, like this: class MyException(BaseException): def
If I wanted to create my own relational database with a modern language to
I wanted to create smth similar to this one Kansas county map where user
I wanted to create one js file which includes every js files to attach
I just wanted to create my own simple document using the agility pack so
I wanted to know if there is any system which allow me to create
I have a problem over here. You see, I wanted to create my own
I wanted to create my own template for the admin-generator, so I've followed a
This is mostly a theory question, for example if I wanted to create my
I wanted to create an extension of java.text.Format but I do not know what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.