Codeigniter分页和.htaccess

时间:2014-08-01 21:05:46

标签: php .htaccess codeigniter mod-rewrite pagination

我在控制器中有这个:

function index(){


    $this->show();

}

function show($start=0){
    $start = $this->uri->segment(3);

    if(trim($start)==''){
        $start = 0;
    }

    $this->load->model('post');
    $data['posts'] = $this->post->get_posts(4,$start);

    $this->load->library('pagination');
    $config['base_url']=base_url().'posts/show/';
    $config['total_rows']=$this->post->get_posts_count();
    $config['per_page'] = 4;
    $config['full_tag_open'] = '<ul class="tsc_pagination tsc_paginationA tsc_paginationA01">';
    $config['full_tag_close'] = '</ul>';
    $config['prev_link'] = '&lt;';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '&gt;';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="current"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';

    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';

    $config['first_link'] = '&lt;&lt;';
    $config['last_link'] = '&gt;&gt;';


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

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


    $this->load->model('about_me');
    $data['about_me'] = $this->about_me->get_about_me();

    $this->load->model('sponsors');
    $data['sponsors'] = $this->sponsors->get_sponsors();


    $this->load->view('post_index',$data);
}

这在htaccess:

RewriteEngine on 
RewriteCond $1 !^(index\.php|css|uploads|assets|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

不知何故,当我点击分页链接时,图像被破坏了。我认为问题出在.htaccess文件中,但我无法弄明白。请帮忙。

1 个答案:

答案 0 :(得分:0)

如果图像路径的实际代码是:

<?php base_url();?>uploads/<?php echo $posts[$i]->image;?>

那就是你的问题。 <php base_url()?>没有回应任何事情;您的实际路径为uploads/<?php echo $posts[$i]->image;?>

只需将开头更改为<php echo base_url()?>即可。

(如果您还没有在那里使用它,则可能需要将http://添加到基本网址的开头。否则,它仍然看起来像一个相对链接。)