For long enough I have been using codeignter , its classes are really good,easy and useful.
I am trying to integrate Pagination class in my custom php framework, found in /base/system/libraries folder of CI setup, before I have successfully integrated Table class to create dynamic tables with php data in my frmework.
Here I am facing problem with $CI =& get_instance(); in /base/system/libraries/Pagination.php, which gets instantiate in controller.php .
And its throwing error because I am not using whole controller , but just its classes.
Is there any solution by which I can use Pagination class , without get_instance().
2 Answers
$CI =& get_instance();
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
if ($CI->input->get($this->query_string_segment) != $base_page)
{
$this->cur_page = $CI->input->get($this->query_string_segment);
// Prep the current page - no funny business!
$this->cur_page = (int) $this->cur_page;
}
}
else
{
if ($CI->uri->segment($this->uri_segment) != $base_page)
{
$this->cur_page = $CI->uri->segment($this->uri_segment);
// Prep the current page - no funny business!
$this->cur_page = (int) $this->cur_page;
}
}
with
if(isset($_GET['cur_page'])){
$this->cur_page = $_GET['cur_page'];
}else{
$this->cur_page = 1;
}
&
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
$this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
}
else
{
$this->base_url = rtrim($this->base_url, '/') .'/';
}
remove this.
Call it like ,
include_once(LIB_DIR.'/pagination.class.php');
$pagination = new Pagination();
$config['base_url'] = 'http://testme.com/stats.php?cur_page=';
$config['total_rows'] = 200;
$config['per_page'] = 20;
$pagination->initialize($config);
echo $pagination->create_links();
Comments
Pagination class doesn't depend on the CI all that much. You can simply rewrite it a bit to find and replace all references to the "outside" with correct data it tries to allocate. Then Pagination will work without any interaction with the CI and you'll be able to use it in your framework.
1 Comment
Debugger
Done.. Removed all the CI instances.
include_once(LIB_DIR.'/Table.php');$table = new Table('default_template');$table->set_heading($dataHeader);$table->generate();etc