CodeIgniter 中页码后面有段
我想知道 CodeIgniter 是否允许页码后面的段以及执行此操作的最佳方法是什么?
$config['base_url'] = '/controller/view/pg/';
我需要我的分页也传递这个:
/controller/view/pg/1/v/l/ rpp/20
...等
我遇到了多个问题,因为我使用 $this->uri->uri_to_assoc(n)
因为我将要使用的段数需要...
我需要能够将值传递到每个页面,目前我不知道该怎么做。
您是否认为最好的方法是始终将分页移至所有其他段的末尾?看来这也会导致问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
杰森,您自己制造这个问题只是因为您不知道哪些部分是控制器/方法的一部分,以及哪些部分是您认为相关的。
首先,我会告诉您坚持一种方法,即将其附加到末尾(这是从 uri 中的用户角度来看,而不是您的路由配置):
上面的格式在后端意味着类似这样的内容:
/view/
是控制器,page
是控制器中的方法,那么您将使用$this->uri->uri_to_assoc(4)< /code> (第四个元素,是开始的名称)。
这样您就可以正确捕获页码
1233
以及与其相关的所有数据。作为建议,我会警告不要使用不可读的变量,它会导致混乱,并且不会使您的网站 url SEO 友好(谁知道 /v/p/123/v/l/20 最终意味着什么?)。
如果您在 uri 路由方面遇到问题,请始终使用您的
$this->output->profiler(TRUE);
。除非确实需要,否则不要弄乱您的路由配置,这可能会导致混乱,从而使您的测试变得复杂。编辑
我造成了混乱,因为根据您的问题,您可以将其解释为来自 config.php 文件或分页类位置的路由问题。我从第一种方法中采取了它。
为了澄清你需要简单地坚持一个干净的 url 方法,如果你使用 uri_to_assoc,那很好。但请不要忘记分页的页码。
您可以通过将页码设置为 uri 中的最后一个元素来解决此问题
Last:
/view/page/1233/name/blue-skies/user/12/20
其中
20
是由分页生成的页码,其他是您用于任何用途的段。在这种情况下,您可以设置
$config['uri_segment'] = 6;
,并且$config['base_url'] = '/view/page/1233/'.$this ->uri->assoc_to_uri($uri_segments);
其中:
IF
未知您有多少个段(例如动态 $uri_segments 数组),使用 $this->uri->total_segments() 来计算总段数,那么您的分页就是该分页的+1(最后一个)。
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):
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:
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).是的,这是可以做到的。
方法是在分页配置数组中,'uri_segment'应该是变量:
$config['uri_segment'] = $segment_offset;
$segment_offset 可以通过在 URI 中查找“/pg/”(来自您的示例)来计算。
示例代码:
Yes, that can be done.
The way to do it is in pagination configuration array, 'uri_segment' should be variable:
$config['uri_segment'] = $segment_offset;
$segment_offset can be calculated by looking for '/pg/'(from your example) in the URI.
Example code: