用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1831|回复: 1
收起左侧

[讨论/交流] ci分页类的问题在C下分页可以正常显示在V下不能显示

[复制链接]
发表于 2013-6-2 22:13:33 | 显示全部楼层 |阅读模式
代码在附件中。在C中可以显示出分页。在V 中不能显示分页。
C
----------------------------------------------------------------------------------------------------------------
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hell extends CI_Controller {

  function __construct()
{
   parent::__construct();
   $this->load->helper('url');
   
  }

  function index()
   {  
     
     $this->load->model('mhome2');
     $db3['category']=$this->mhome2->get_category();
     $db3['tit']="ci主页页标题测试";
     $this->load->view('header',$db3);
   $this->load->view('index');
  $this->load->view('footer');
  }
   
   function category()
  {
     $this->load->model('mhome2');
     $db3['category']=$this->mhome2->get_category();
  //$db3['textname']=$this->mhome2->get_article($this->uri->segment(3));
  $db3['minname']=$this->mhome2->get_category_name($this->uri->segment(3));
     $db3['tit']="ci栏目页标测试";
     $this->load->view('header',$db3);
  $config['base_url'] ='http://127.0.0.1/ci/index.php/hell/category/'.$this->uri->segment(3).'/';
                        
        $config['total_rows'] =$this->mhome2->sele_num_row($this->uri->segment(3));
        $config['per_page'] = '1';
  $config['uri_segment'] = '3';
        $config['num_links'] = '5';
        $config['full_tag_open'] = '<p>';
  $config['full_tag_close'] = '</p>';
        $config['first_link'] = '第一页';
  $config['last_link'] = '尾页';
  $config['next_link'] = '下一页';
  $config['prev_link'] = '上一页';
        $this->pagination->initialize($config);
        $db3['textname']=$this->mhome2->get_page($this->uri->segment(3),$this->uri->segment(4,0),$config['per_page']);
  // print_r ($db3);
  
   
   $this->load->view('category',$db3);
  echo $this->pagination->create_links();
  $this->load->view('footer');
}

function content()
  {
   
     $this->load->model('mhome2');
     $db3['category']=$this->mhome2->get_category();
  $db3['textname']=$this->mhome2->get_article($this->uri->segment(3));
  $db3['minname']=$this->mhome2->get_category_name($this->uri->segment(3));
  $db3['get_article_content']=$this->mhome2->get_article_content($this->uri->segment(3));
  $db3['get_comment']=$this->mhome2->get_comment($this->uri->segment(3));
     $db3['tit']="ci内容页标测试";
  //print_r ($db3);
   $this->load->view('header',$db3);
   $this->load->view('content',$db3);
   $this->load->view('footer');
  }

function comment_ok()
  {      
   if ($this->input->post('submit')) {
    $this->load->model('mhome2');
    $query = $this->mhome2->insert_comment();
    if ($query) {
      redirect('hell/content/'.$this->input->post('article_id'));
     
     }
   
   }
  }
  
   
     
}


V
-----------------------------------------------------------------------------------------------------------------
<div id="bodyBottom">
<!--news start -->
<!--news end -->
<!--services start -->
<div id="service">
<h2>
<?foreach ($minname as $row):?>
<?=$row->category_name?>
<?endforeach;?>
</h2>
<ul>
<?foreach ($textname as $row):?>
<li><?=anchor('hell/content/'.$row->id,$row->title)?></li>
<?endforeach;?>
</ul>
<div id="page_style">
<?php  $this->pagination->create_links();
var_dump($this->pagination);?>
</div>
<br class="spacer" />
</div>
<!--services end -->
<!--member start -->
<!--member end -->
<br class="spacer" />
</div>
<!--bodyBottom end -->




M
---------------------------------------------------------------------------------------------------------------------
<?php
class Mhome2 extends CI_Controller  {
  function  __construct()
  {
   parent::__construct();
      $this->load->database();
  }  
   
  function get_category()
  {  
   $query=$this->db->query('SELECT * FROM category');
   return $query->result();
  }
  
  
  function get_category_name($category_id)
  {
   $query = $this->db->query("SELECT * FROM category WHERE category_id = $category_id");
   return $query->result();
  }
  
  function get_article($category_id)
  {
   $query = $this->db->query("SELECT * FROM article WHERE category_id=$category_id");
   return $query->result();
  }
  
  
  function get_article_content($id)
  {
   $query = $this->db->query("SELECT * FROM article WHERE id = $id");
   return $query->result();
  }
  
  
  function get_comment($article_id)
  {
   $query = $this->db->query("SELECT * FROM comments WHERE article_id=$article_id");
   return $query->result();
  }
  
  
  function insert_comment()
  {
    $content = $this->input->post('content');
    $article_id = $this->input->post('article_id');
    $author = $this->input->post('author');
    $this->db->query("INSERT INTO comments(id,article_id,content,author,last_date)VALUES('','$article_id','$content','$author',now())");
    return $this->db->affected_rows();
  }
  
  function sele_num_row($category)
       {
       $query = $this->db->query("SELECT * FROM article WHERE category_id=$category");
   return $query->num_rows();
       }
  
   function get_page($category,$offset,$num)
       {
    $query = $this->db->query("SELECT * FROM article WHERE category_id=$category  order by id  desc  limit $offset,$num");
   return $query->result();
   
   }
  
}


controllers.rar

5.16 KB, 下载次数: 0

 楼主| 发表于 2013-6-2 22:14:33 | 显示全部楼层
哪位指点一二

本版积分规则