Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination uri_segment Config Issues
  • Hello there, I am in the process of finalizing a CMS using FuelPHP. A feature of this CMS is a simple image gallery that displays a logged in user's uploaded images. I have read the documentation on the Pagination Class (http://fuelphp.com/docs/classes/pagination.html) and have gotten it mostly setup. My images are displaying on the page based upon the limit that I set up in the set_config method. My only issue is that the uri_segment isn't exactly working the way which I assumed it would. In fact, I am not entirely sure exactly what the uri_segment is. The URL to the gallery is http://localhost:8888/asl1105/jbuff/cms/admin/media. I have tried setting the uri_segment to everything from zero to 12 in an attempt to find the value which works. However, I have been unsuccessful. When I attempt to go to the next page with a URL of: http://localhost:8888/asl1105/jbuff/cms/admin/media/2 I simply get my 404 page. Any help would be greatly appreciated!
    :)
  • Are your routes setup to accept the additional URI segments?
  • NOTE: Before reading this post, please read the next. I believe I may have found a bug.
    Harro Verton wrote on Thursday 12th of May 2011:
    Are your routes setup to accept the additional URI segments?

    Actually, no. I was thinking that may be the issue, however I did not see the documentation say anything about routes. How would I go about setting the routes.php file correctly? I assume like one of these:
    'admin/media/:pagenumber'  => 'admin/media/$1';
    'admin/media/:any'  => 'admin/media/$1'
    
    However, this does not work. It does take me back to my media page, however the first page's images are still shown. EDIT:
    In turn, this code gives me an error
    'admin/media/:pagenumber'  => 'admin/media/$1';
    
    My Media controller:
    $paginationConfig = array(
          'pagination_url' => 'http://localhost:8888/asl1105/jbuff/cms/admin/media/',
          'total_items' => count($articleImages),
          'per_page' => 2,
          'uri_segment' => 3,
      );
      
      Pagination::set_config($paginationConfig);
      
      $data['example_data'] = DB::select('*')->from('images')->where('imageType', '=', 2)->and_where('authorID', '=', $authorID)
                                                    ->limit(Pagination::$per_page)
                                                    ->offset(Pagination::$offset)
                                                    ->execute()
                                                    ->as_array();
    

    My View's PHP:
    <ul id="imggallery">
         <?php
          if(count($example_data) > 0)
          &#123;
           foreach($example_data as $image)&#123;
            
            echo '<li>';
             echo Asset::img($image['imagePath'], array('alt' => $image['alt']));
             echo '<div class="imgtitle">'. $image['title'] .'</div>';
            echo '</li>';
           }
          }
         ?> 
        </ul>
        <?php echo Pagination::create_links(); ?>
    

    I am pretty confused as to how I should set up the routes. Any help would be greatly appreciated.
  • SOLVED. I believe I may have found a bug. [url=http://localhost:8888/asl1105/jbuff/cms/docs/classes/pagination.html]Per the documentation[/url], there are two ways of setting the pagination configuration. Straight from the documentation
    // Config::set('pagination', $config); // you can use this too!
    Pagination::set_config($config);
    

    However, I could only use the former method of setting the pagination configuration. It turned out I was actually setting the route correctly when I set 'admin/media/:pagenumber' => '/admin/media/', . If I don't hear from someone on the Fuel team on this thread, I will file a bug report tomorrow. Thanks for your help, WanWizard. I appreciate it.
  • The Pagination class fetches the global config during class init, which happens when the autoloader loads the class. If you use Config::set() after the Pagination class is loaded, it has no effect, and you have to use Pagination::set_config().

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion