0

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().

5
  • 2
    You seem to have the whole concept of using codeigniter libraries upside down. Can you post some code of what you're trying to do? Commented Jan 17, 2012 at 5:59
  • If that's your modus operandi, you are better off using Zend Framework maybe.What do you mean "I'm not using controller anywhere"? So you just took CI's pagination class in your personal project, without the rest of the framework? Commented Jan 17, 2012 at 6:14
  • @JosephSilber , Yes i know its weird way to use it ;-) , but I am just including class file.And using its function by creating object.I am using CI's table class as following : include_once(LIB_DIR.'/Table.php');$table = new Table('default_template');$table->set_heading($dataHeader);$table->generate(); etc Commented Jan 17, 2012 at 10:46
  • @DamienPirsy , I have edited question .You will understand now. Commented Jan 17, 2012 at 10:49
  • DOne.. Removed all the CI instances. Commented Jan 17, 2012 at 14:16

2 Answers 2

1
    $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();
Sign up to request clarification or add additional context in comments.

Comments

0

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

Done.. Removed all the CI instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.