dongranding3909 2012-01-27 14:08
浏览 32
已采纳

在CodeIgniter中具有页码之后的段

I am wondering if CodeIgniter allows segments after the page number and what is the best way to do this?

$config['base_url'] = '/controller/view/pg/';

I need my paging to pass this also:

/controller/view/pg/1/v/l/rpp/20 ... etc

I have ran into multiple problems because I am using $this->uri->uri_to_assoc(n) because of the number of segments I will be needing...

I need to be able to pass values to each page, and at this point I'm not sure how to do it.

Do you think the best way to do this is to always move the paging to the end of all other segments? It seems that this leads to problems also.

  • 写回答

2条回答 默认 最新

  • duanji1043 2012-01-27 14:19
    关注

    Jason, you are making the problem yourself simply because you loose track of what segements are part of the controller/method, and which are your segments that you find relevant.

    I would first of all tell you to stick to one method say to append it to the end (this is from the users perspective in the uri, not your route config):

    /view/page/1233/name/blue-skies/pg/20
    

    The above format would mean something like this on the backend: /view/ is the controller, page is your method in the controller, then you would use $this->uri->uri_to_assoc(4) (4th element, being name to start).

    That way you correctly capture your page number 1233 and then all relevant data to it.

    As a suggestion, I would caution against using unreadable variables, it leads to confusion and does NOT make your site url SEO friendly (who knows what /v/p/123/v/l/20 means in the end?).

    Always user your $this->output->profiler(TRUE);, if you are having trouble with uri routing. Don't mess with your route config unless you REALLY need to, this may lead to confusion, which complicates your testing.

    EDIT

    I created confusion because based on your question you could interpret it as a routing issue from the position of the config.php file OR the pagination class. I took it from the first approach.

    To clarify you need to simply stick to a clean url method, if you use uri_to_assoc, thats fine. But just don't loose track of your page number for the pagination.

    You can solve this by making the page number the last element in your uri

    Last: /view/page/1233/name/blue-skies/user/12/20

    Where the 20 is the page number that is generated by pagination, the other are segments you use for whatever.

    You would set your $config['uri_segment'] = 6; in this case, and your $config['base_url'] = '/view/page/1233/'.$this->uri->assoc_to_uri($uri_segments);

    Where:

    $uri_segments = array(
     'name' => 'blue-skies',
     'user' => '12');
    

    IF

    It is unknown how many segments you have (say a dynamic $uri_segments array), use $this->uri->total_segments() to count total segments, then your pagination one is the +1 to that (last).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用