title: CodeIgniter custom pagination helper
body: <p>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.</p>
  
  <pre><code> &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
       if (!function_exists('pagination'))
  
  {
  
      function prikazi($per_page, $page, $url, $total)
      {
          $CI =&amp; 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 &gt; 1)
      {  
         $pagination .= "&lt;ul class='pagination'&gt;";
             $pagination .= "&lt;li class='details'&gt;Page $page of $lastpage&lt;/li&gt;";
          if ($lastpage &lt; 7 + ($adjacents * 2))
          {  
              for ($counter = 1; $counter &lt;= $lastpage; $counter++)
              {
                  if ($counter == $page)
                      $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                  else
                      $pagination.= "&lt;li&gt;&lt;a href='{$url}$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
              }
          }
          elseif($lastpage &gt; 5 + ($adjacents * 2))
          {
              if($page &lt; 1 + ($adjacents * 2))    
              {
                  for ($counter = 1; $counter &lt; 4 + ($adjacents * 2); $counter++)
                  {
                      if ($counter == $page)
                          $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                      else
                          $pagination.= "&lt;li&gt;&lt;a href='{$url}$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                  }
                  $pagination.= "&lt;li class='dot'&gt;...&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}$lpm1'&gt;$lpm1&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}$lastpage'&gt;$lastpage&lt;/a&gt;&lt;/li&gt;";     
              }
              elseif($lastpage - ($adjacents * 2) &gt; $page &amp;&amp; $page &gt; ($adjacents * 2))
              {
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}1'&gt;1&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}2'&gt;2&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li class='dot'&gt;...&lt;/li&gt;";
                  for ($counter = $page - $adjacents; $counter &lt;= $page + $adjacents; $counter++)
                  {
                      if ($counter == $page)
                          $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                      else
                          $pagination.= "&lt;li&gt;&lt;a href='{$url}$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                  }
                  $pagination.= "&lt;li class='dot'&gt;..&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}$lpm1'&gt;$lpm1&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}$lastpage'&gt;$lastpage&lt;/a&gt;&lt;/li&gt;";     
              }
              else
              {
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}1'&gt;1&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li&gt;&lt;a href='{$url}2'&gt;2&lt;/a&gt;&lt;/li&gt;";
                  $pagination.= "&lt;li class='dot'&gt;..&lt;/li&gt;";
                  for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter &lt;= $lastpage; $counter++)
                  {
                      if ($counter == $page)
                          $pagination.= "&lt;li&gt;&lt;a class='current'&gt;$counter&lt;/a&gt;&lt;/li&gt;";
                      else
                          $pagination.= "&lt;li&gt;&lt;a href='{$url}$counter'&gt;$counter&lt;/a&gt;&lt;/li&gt;";                   
                  }
              }
          }
  
          if ($page &lt; $counter - 1){
              $pagination.= "&lt;li&gt;&lt;a href='{$url}$next'&gt;Next&lt;/a&gt;&lt;/li&gt;";
             // $pagination.= "&lt;li&gt;&lt;a href='{$url}$lastpage'&gt;Last&lt;/a&gt;&lt;/li&gt;";
          }else{
              //$pagination.= "&lt;li&gt;&lt;a class='current'&gt;Next&lt;/a&gt;&lt;/li&gt;";
             // $pagination.= "&lt;li&gt;&lt;a class='current'&gt;Last&lt;/a&gt;&lt;/li&gt;";
          }
          $pagination.= "&lt;/ul&gt;\n";     
      }          
          return $pagination;
      }
  }
  </code></pre>
  
  <p>And in my other file i try to echo like this  : </p>
  
  <pre><code>  $this-&gt;load-&gt;helper('pagination');
      echo prikazi($bypage,$page,$link,$total); 
  </code></pre>