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

[已解决] 求救啊,分页错误

[复制链接]
发表于 2010-1-16 21:34:19 | 显示全部楼层 |阅读模式
我在首页分页,首页能显示,但点击分页的时候错误:
404 Page Not Found
The page you requested was not found.

点击第二页url上面是:
http://localhost/ci/index.php/3

我的代码:
function index()

{


$this->load->library('pagination');

$config['base_url'] = base_url().$this->config->item('index_page');

$config['uri_segment'] = 3;

$config['per_page'] = 3;

$config['full_tag_open'] = '<p>';

$config['full_tag_close'] = '</p>';

$config['cur_tag_open'] = '<b>';

$config['cur_tag_close'] = '</b>';

$config['next_link'] = '>';

$config['prev_link'] = '<';

$fields='gid';

$query=$this->Guestbook->getguestbook($fields);

$config['total_rows'] = $query->num_rows();

$this->pagination->initialize($config);

$query->free_result();

$page = $this->uri->segment(3, 0);

$fields='gid, title, content, pubtime, rednum';

$where=null;

$limit= array('start'=>$config['per_page'],
   
  'end'=>$page
   
);

$join='fa_user_profile';

$typebegin='id';

$typeend='userid';



$query = $this->Guestbook->getguestbook($fields, $limit);

if ($query->num_rows()>0)

{

$i=1;

foreach ($query->result() as $row)

{
              /***  $data['user'][$i]['show_edit_link'] =
                    ($row->role != 'admin' AND $row->role != 'superadmin');
                $data['user'][$i]['show_delete_link'] =
                    ($row->role != 'admin' AND $row->role != 'superadmin');**/

                // then we just fill the infos

$data['guestbook'][$i]['gid']= $row->gid;

$data['guestbook'][$i]['title']= $row->title;

$data['guestbook'][$i]['content']= $row->content;

$data['guestbook'][$i]['pubtime']= $row->pubtime;

$data['guestbook'][$i]['rednum']= $row->rednum;



$i++;

}



$query->free_result();

}else{

show_error('还没有留言类容!');

}



$data['pagination_links'] = $this->pagination->create_links();

$data['heading'] = '留言';
        $this->load->vars($data);

$this->load->view($this->_container);



//$this->output->enable_profiler(TRUE);

}
发表于 2010-1-16 21:36:22 | 显示全部楼层
$config['base_url'] = base_url().$this->config->item('index_page');
这句错了,必须是当前控制器的当前方法,而不能是 http://domain/index.php/3 这样的。

楼主应该仔细看一下手册 CI URL 相关章节。

PS: 千万不能照猫画虎,例子直接拿过来肯定是不行的,要多动脑筋。
 楼主| 发表于 2010-1-16 21:54:30 | 显示全部楼层
谢谢,找到问题了,$config['base_url']没有添加控制器名称和index
已经搞定了~~
谢谢

本版积分规则