[eluser]treadsoftley[/eluser]
Thanks Mario... I was just about to embark on this in order to sort out pagination problems caused when splitting a large article into pages.
In the spirit of one good turn .... I have included snippets from my code to show how I split and page an article using this adapted pagination class.
Code:
//Check content (article) for page breaks as denoted by '[break]' tag
$doPaging = strpos($content, '[break]');
//if a paged article or on a given page of that article
//$page relates to the paging uri_segment
if ($page > 0 || $doPaging)
{
// get paged content params
$paging = $this->get_page($page, $content);
if ($paging['content'] != '')
{
//as I also page db records I have added this pagination
//as a new library class called 'Pageit'
//library otherwise works as nomal
$this->load->library('pageit');
$config['base_url'] = site_url().'yourUrl/';
$config['total_rows'] = $paging['total_pages'];
$config['per_page'] = $paging['per_page'];
$config['uri_segment'] = 5;
//initialise paging
$this->pageit->initialize($config);
//add content and pagination
$content = $paging['content'].'<br /><br />';
$content .= $this->pageit->create_links();
}
}
Send to your template etc >>>>
And the get page function
Code:
function get_page($page, $data)
{
$paging=array();
$paging['content'] = '';
$paging['per_page'] = 1;
//split body into pages then count them
$body_pages = preg_split("/\[break\]/", $data);
$total_pages = count($body_pages);
//page to page total failsafe
if (($page > $total_pages) || ($page < 1)) {
$page = 1;
}
// select page to display
$paging['content'] = $body_pages[$page-1];
$paging['total_pages'] = $total_pages;
return $paging;
}
All fairly straightforward but the page linking went awry with the built-in pagination class.