Skip to content

Instantly share code, notes, and snippets.

@Tjoosten
Created January 22, 2017 17:23
Show Gist options
  • Save Tjoosten/357106e01f6a775265596166cff6dc41 to your computer and use it in GitHub Desktop.
Save Tjoosten/357106e01f6a775265596166cff6dc41 to your computer and use it in GitHub Desktop.
ERROR: View is always returning the four first records of the db
/**
* Get the front-end for the nws items.
*
* @see GET|HEAD: http://www.domain.tld/news
* @return blade view.
*/
public function index()
{
// Needed data for the pagination.
$query = Articles::with(['comments', 'author', 'categories']);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->pagination->initialize($this->paginationConfig(base_url('news/'), $query->count(), 4, 3));
$data['title'] = 'Nieuws';
$data['news'] = $query->skip($page)->take(4)->get();
$data['categories'] = NewsCategories::all();
$data['links'] = $this->pagination->create_links();
return $this->blade->render('news/index', $data);
}
/**
* Pagination config
*
* @param string $baseUrl The base url for the page.
* @param int $totalRows The amount off rows of the query.
* @param int $perPage Amount of data rows per page.
* @param int $segment The URI segment.
* @return array $config
*/
public function paginationConfig($baseUrl, $totalRows, $perPage, $segment)
{
$config['base_url'] = $baseUrl;
$config['total_rows'] = $totalRows;
$config['per_page'] = $perPage;
$config['uri_segement'] = $segment;
$config['num_links'] = round($config['total_rows'] / $config['per_page']);
$config['page_query_string'] = true;
// $config['use_page_numbers'] = TRUE;
$config['query_string_segment'] = 'page';
$config['full_tag_open'] = '<ul class="pagination pagination-sm">';
$config['full_tag_close'] = '</ul><!--pagination-->';
$config['first_link'] = '&laquo; First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last &raquo;';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Volgende &rarr;';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '&larr; Vorige';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
// $config['display_pages'] = FALSE;
//
$config['anchor_class'] = 'follow_link';
return $config;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment