Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    Problem initializing a class

    Hi Guys,

    For some strange reason my class doesn't seem to want to initialize. This exact script works on my website currently, but is giving me a problem on my local development pc. Not quite sure what's wrong. This is a custom wordpress theme so its split up funky. I keep getting this error Fatal error: Call to a member function display_pages() on a non-object.

    This is inside my page template.
    PHP Code:
    include_once( LP_CLASSES_DIR '/pagination-class.php');

    /* Get the records */
    $drawing_count HistData_Model::total_drawing_dates();

    /* Define pagination */
    $pages = new Pagination;
    $pages->items_total $drawing_count[0]['count(*)'];
    $pages->mid_range 7;
    $pages->paginate();


    echo 
    $pages->display_pages();
    echo 
    $pages->display_items_per_page();
    echo 
    $pages->display_jump_menu();

    foreach(
    $drawings_array as $new_drawing):
        echo 
    $new_drawing//This comes from further up and populates fine when you print array out.
    endforeach;
    echo 
    "<br />";
    echo 
    $pages->display_pages(); 
    this is my pagination class
    PHP Code:
    <?php

    class Pagination{
        var 
    $items_per_page;
        var 
    $items_total;
        var 
    $current_page;
        var 
    $num_pages;
        var 
    $mid_range;
        var 
    $low;
        var 
    $high;
        var 
    $limit;
        var 
    $return;
        var 
    $default_ipp 10;
        var 
    $querystring;
        
        function 
    Pagination(){
            
    $this->current_page 1;
            
    $this->mid_range 7;
            
    $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
        }
    //EOF

        
    function paginate(){
            if( isset( 
    $_GET['ipp'] ) ): $selected_ipp $_GET['ipp']; else: $selected_ipp $this->default_ipp; endif;
            if( isset( 
    $_GET['page'] ) ): $selected_page $_GET['page']; else: $selected_page 1; endif;
            
    $mod explode("?"$_SERVER['REQUEST_URI']);
            
    $php_self $mod[0];
            if(
    $selected_ipp == 'All'): //changed from $_GET
                
    $this->num_pages ceil($this->items_total/$this->default_ipp);
                
    $this->items_per_page $this->default_ipp;
            else:
                if(!
    is_numeric($this->items_per_page) OR $this->items_per_page <= 0$this->items_per_page $this->default_ipp;
                
    $this->num_pages ceil($this->items_total/$this->items_per_page);
            endif;
            
    $this->current_page = (int) $selected_page// must be numeric > 0
            
    if($this->current_page Or !is_numeric($this->current_page)) $this->current_page 1;
            if(
    $this->current_page $this->num_pages$this->current_page $this->num_pages;
            
    $prev_page $this->current_page-1;
            
    $next_page $this->current_page+1;

            if(
    $_GET):
                
    $args explode("&",$_SERVER['QUERY_STRING']);
                foreach(
    $args as $arg):
                    
    $keyval explode("=",$arg);
                    if(
    $keyval[0] != "page" And $keyval[0] != "ipp"$this->querystring .= "&" $arg;
                endforeach;
            endif;

            if(
    $_POST):
                foreach(
    $_POST as $key=>$val):
                    if(
    $key != "page" And $key != "ipp"$this->querystring .= "&$key=$val";
                endforeach;
            endif;

            if(
    $this->num_pages 10):
                
    $this->return = ($this->current_page != And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"".$php_self."?page=$prev_page&ipp=$this->items_per_page$this->querystring\">&laquo; Previous</a> ":"<span class=\"inactive\" href=\"#\">&laquo; Previous</span> ";

                
    $this->start_range $this->current_page floor($this->mid_range/2);
                
    $this->end_range $this->current_page floor($this->mid_range/2);

                if(
    $this->start_range <= 0):
                    
    $this->end_range += abs($this->start_range)+1;
                    
    $this->start_range 1;
                endif;
                if(
    $this->end_range $this->num_pages):
                    
    $this->start_range -= $this->end_range-$this->num_pages;
                    
    $this->end_range $this->num_pages;
                endif;
                
    $this->range range($this->start_range,$this->end_range);

                for(
    $i=1;$i<=$this->num_pages;$i++):
                    if(
    $this->range[0] > And $i == $this->range[0]) $this->return .= " ... ";
                    
    // loop through all pages. if first, last, or in range, display
                    
    if($i==Or $i==$this->num_pages Or in_array($i,$this->range)):
                        
    $this->return .= ($i == $this->current_page And $selected_page != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"".$php_self."?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
                    endif;
                    if(
    $this->range[$this->mid_range-1] < $this->num_pages-And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
                endfor;
                
    $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($selected_page != 'All')) ? "<a class=\"paginate\" href=\"".$php_self."?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next &raquo;</a>\n":"<span class=\"inactive\" href=\"#\">&raquo; Next</span>\n";
                
    $this->return .= ($selected_page == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"".$php_self."?page=1&ipp=All$this->querystring\">All</a> \n";
            else:
                for(
    $i=1;$i<=$this->num_pages;$i++):
                    
    $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"".$php_self."?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
                endfor;
                
    $this->return .= "<a class=\"paginate\" href=\"".$php_self."?page=1&ipp=All$this->querystring\">All</a> \n";
            endif;
            
    $this->low = ($this->current_page-1) * $this->items_per_page;
            
    $this->high = ($selected_ipp == 'All') ? $this->items_total:($this->current_page $this->items_per_page)-1;
            
    $this->limit = ($selected_ipp == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
        }
    //EOF

        
    function display_items_per_page(){
            
    $mod explode("?"$_SERVER['REQUEST_URI']);
            
    $php_self $mod[0];
            
    $items '';
            
    $ipp_array = array(10,25,50,100,'All');
            foreach(
    $ipp_array as $ipp_opt)    $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
            return 
    "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='".$php_self."?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
        }
    //EOF

        
    function display_jump_menu(){
            
    $mod explode("?"$_SERVER['REQUEST_URI']);
            
    $php_self $mod[0];
            for(
    $i=1;$i<=$this->num_pages;$i++):
                
    $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
            endfor;
            return 
    "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='".$php_self."?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
        }
    //EOF

        
    function display_pages(){
            return 
    $this->return;
        }
    //EOF
    }//EOC

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What line and file is this error from?

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    the problem is when the functions are called from the class at these lines, keeps thinking it is a non object, but when i check to see if the class is loaded it works fine. Its definitely loaded because I was receiving internal errors in the class about missing $_GET['page'] and $_GET['ipp']. I just plugged in a simple if statement to squash those bugs.

    PHP Code:
    echo $pages->display_pages();
    echo 
    $pages->display_items_per_page();
    echo 
    $pages->display_jump_menu(); 

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Is this where the error is indicated though by the line and file provided in the error code? It should never make it to this point if $pages isn't a Pagination object as it would fail before this point.
    I'm not raising to question whether its loaded, that much we can see since it would have failed prior to this point. I also see no globalization that would cause the problem. So the problem is I can't see what is causing the problem. This is why I'm curious of the page and line number; from here it looks like its neither of these blocks.

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    Yeah, I figured it out now. I kept moving that line around the code until it broke. As it turned out there was a variable being called in my header that overwrote the $page instance. So as soon as i renamed it differently everything lit up like a christmas tree. Thanks for the help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •