如何处理codeigniter中的多个参数 [英] how to handle multiple parameters in codeigniter

查看:152
本文介绍了如何处理codeigniter中的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户以两种方式查看图书:列表视图或网格视图。
所以我想接收一个参数作为网格或列表,并显示视图页面作为参数接收。
但是我不知道如何处理这个在codeigniter控制器。



还有我已经在我的页面分页。我的URL显示 http://localhost/thebestbookfinder.com/viewallbooks/books/pgn/9 ,在这里我想传递一个参数,如view = grid或view =



所以可能是我的url将是:
http:// localhost / thebestbookfinder.com/viewallbooks/books/pgn/9/grid
那么我将如何在我的控制器中收到它。



请帮我解决这个问题。

解决方案

为什么不像你获得分页号码的方式 $ page =($ this-> uri-> segment(4))? $ this-> uri-> segment(4):0;



您可以执行 $ viewType =($ this-> uri-> segment(5))? $ this-> uri-> segment(5):'list'; ,如果你想传递给视图 $ data ['viewType'] = $ viewType; c>



,然后稍后在调用视图的部分 $ this-> load-> view('commonfiles / booksview',$ data); ,你可能已经创建了两个单独的视图一个列表和一个网格视图,并根据 $ viewType 或在一个视图文件中同时包含这两个代码,并从选择 $ data ['viewType'] 。我建议第一个选项。



同样在CodeIgniter中,你可以传递URI段作为函数的参数与它们在URI中的顺序,像这个例子函数书($ hasPagination,$ paginationNumber,$ viewType ='list'){将从此URI获取参数 http://localhost/thebestbookfinder.com/viewallbooks/ books / pgn / 9 / grid ,并且值将被分配如下:
$ hasPagination ='pgn';
$ paginationNumber = 9;
$ viewType ='grid';



也可以照常传递GET参数 viewallbooks / books ?pagination = true& pgn = 9& viewType = list ,然后使用内置函数处理每一个 $ viewType = $ this-> input-> ; get('viewType') $ pgn = $ this-> input-> get('pgn') p>

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.

解决方案

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.

这篇关于如何处理codeigniter中的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆