dongyongju9560 2013-02-01 08:40
浏览 26
已采纳

如何在codeigniter中处理多个参数

i am allowing user to view books in two ways: either "list" view or by "grid" view. so i thought to receive a parameter as grid or list and show the view page as parameter received. But i don't know how to handle this in controller of codeigniter.

And also i already have pagination on my page. My url is showing http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/9 and in this i want to pass a parameter like view=grid or view=list and i have to receive it in my controller.

so may be my url will be : http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/9/grid then how i will receive it in my controller.

Please help me to solve this problem.

  • 写回答

1条回答 默认 最新

  • douguxun6866 2013-02-01 09:02
    关注

    Why don't you do it like the way you are getting the pagination number here $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

    You could do this $viewType = ($this->uri->segment(5)) ? $this->uri->segment(5) : 'list'; and if you want to pass it to the view $data['viewType '] = $viewType;

    and then later in the part that you call the view $this->load->view('commonfiles/booksview',$data);, you could either have already created 2 separate views one for list and one for grid view and call the appropriate one depending on the $viewTypeor have both code in one view file and choose from there which to show with an if statement comparing the $data['viewType']. I recommend the first option.

    Also in CodeIgniter you can pass the URI segments as function's parameters with the order they are in the URI, like this example function books($hasPagination, $paginationNumber, $viewType = 'list'){ will get the parameters from this URI http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/9/grid and the values will be assigned like this: $hasPagination = 'pgn'; $paginationNumber = 9; $viewType = 'grid';

    Also you can pass GET parameters as usual viewallbooks/books?pagination=true&pgn=9&viewType=list and then handle each one of them with the built in function like this $viewType = $this->input->get('viewType'), $pgn = $this->input->get('pgn') etc.

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

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统