2012-01-17 93 views
0

足够长的时间我一直在使用codeignter,它的类真的很好,简单而有用。
我正在尝试在我的自定义php框架中将分页类集成到CI设置的/ base/system/libraries文件夹中,然后我成功地将Table类与PHP数据集成在一起以创建动态表。
这里我遇到了/base/system/libraries/Pagination.php中的$CI =& get_instance();问题,它在controller.php中被实例化。 而它的抛出错误是因为我没有使用整个控制器,而只是它的类。
有没有我可以使用分页类,没有get_instance()的任何解决方案。需要使用codeigniter类的核心php

+2

你似乎有使用笨库倒挂的整个概念。你可以发布你想要做的一些代码吗? – 2012-01-17 05:59:46

+0

如果这是你的_modus operandi_,那么最好使用Zend Framework。你是什么意思“我没有在任何地方使用控制器”?所以你只是在你的个人项目中使用CI的分页课程,而没有其余的框架? – 2012-01-17 06:14:32

+0

@JosephSilber,是的,我知道它使用它的奇怪方式;-),但我只是包括类文件。并通过创建object.I使用它的函数。我使用CI的表类如下:'include_once(LIB_DIR。'/ Table .php'); $ table = new Table('default_template'); $ table-> set_heading($ dataHeader); $ table-> generate(); '等 – Debugger 2012-01-17 10:46:08

回答

0

分页类不依赖于CI。您可以简单地重写它,找到并替换所有对“外部”的引用,并使用它尝试分配的正确数据。然后,分页将无需与CI进行任何交互即可工作,并且您可以在您的框架中使用它。

+0

完成..删除了所有的CI实例。 – Debugger 2012-01-17 14:17:30

+0

而且?它解决了问题吗? – Ranty 2012-01-17 15:09:27

+0

是的。我有大多数解决方案作为答案。 – Debugger 2012-01-17 15:54:34

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; 
     } 
    } 

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, '/') .'/'; 
     } 

删除此。

这样称呼它,

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