更新时间:2023-02-15 13:39:56
为什么不像你获得分页号码的方式 $ 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 $viewType
or 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.