首页 文章

使用分页时,Codeigniter url重写问题

提问于
浏览
1

这些天我正在学习codeigniter . 我几天前做了一个自己使用的网站,我今天刚刚应用了分页,但似乎我的网址重写有问题 .

Here is my action inside my controller which grabs list of authors in a category 
    `public function index() {
         $data['main_content'] = "templates/public/audio/author_view";
         $data['authors'] = $this->author_model->get_authors();
         $this->load->view("templates/public/template",$data);
     }`
Here is my function that grabs value from db located inside my author model
      `public function get_authors($type = 0) {
        $this->db->select("author.name,author.image,author.slug");
        $this->db->from("author");
        $this->db->join("album","author.id = album.author_id");
        $this->db->where("album.mime_type",$type);
        $this->db->group_by("author.name");
        $query = $this->db->get();
        return $query->result();
    }`

当我点击其中一位作者 grab 它时,打开所选作者的所有专辑 . 然后网址链接www.xyz.com/audio/album-name
这是我的这条路线的代码 .

$route['audio/(:any)'] = "audio/view_author_album";

在这个阶段,它工作正常 . 但是今天当我申请分页时,我发现这条路线不会为我做更多工作 . 我在索引操作中添加了分页 . 下面你可以看到我的代码

public function index() {
        $config['base_url'] = "http://localhost/mywebsite/audio/index/";
        $config['total_rows'] = $this->author_model->get_total_rows();
        $config['per_page'] = 1;
        $this->pagination->initialize($config);
        $data['main_content'] = "templates/public/audio/author_view";
        $data['authors'] = $this->author_model->get_authors($config['per_page'], $this->uri->segment(3));
        $this->load->view("templates/public/template",$data);
    }

这打开了详细信息http:// localhost / mysite / audio / index / 2

反对这个网址我的路线规则$ route ['audio/(:any)/(:any)'] = "audio/view_album_details";作品 .
它应该 grab 下一页而不是我的详细视图 .

并且url应该类似于http:// localhost / mysite / audio / 2
我也试过$ route ['audio/(:num)'] =“audio /;
如果有人能帮助我解决这个问题,我会非常合适 .

1 回答

  • -1

    我遇到了同样的问题,我通过使用两个相同的路由器来解决它

    $ route ['a-b-c /([a-z0-9-])/([0-9] *)'] =“product / category / $ 1”; $ route ['a-b-c /([a-z0-9-])'] =“product / category /”;

相关问题