douzhong3038 2014-03-12 10:20
浏览 24
已采纳

哪个更好? 从控制器传递参数或使用uri?

I need to make a dynamic page that is something like : example.com/nameofbook/1 - where 1 is the number of the page.

This are 2 parameters.

I know 2 ways of doing it. 1. In controller I have function page($book, $page) 2. Take from the link the parameters with this->uri->segment.

What should I use and why and which one is safer?

Anyhow when I use the controller with 2 parameters the CSS code doesn't load. When I use 1 it loads. my route is something like $route['page/(:any)/(:any)']='main/page/$1/$2'.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dqf35839 2014-03-12 10:30
    关注

    using the $this->uri->segment is exactly the same as using parameters in the controller.. the parameters will get passed to the controller if its part of the URI whether you have defined them in the method or not.

    i.e:

    page() {
        // This will be an array of passed arguments
        $args = func_get_args();
    }
    

    I am not sure why your CSS doesn't load with one method over another. also judging by your URI, your route won't work.. because the 'page' part is not in the URI, so your URI should be example.com/page/nameofbook/1

    either way is 'safe' it makes no difference in the 2 ways you suggest.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大