Cakephp 2.0分页问题。如何传递参数在分页链接? [英] Cakephp 2.0 Pagination issue. How to pass arguments in pagination link?

查看:287
本文介绍了Cakephp 2.0分页问题。如何传递参数在分页链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cakephp 2.0分页问题。如何在分页链接中传递参数?



我传递了

的参数

  $ this-> Paginator-> options(array('url'=> $ this-> request-> query)); 

但在第二页后它不工作。



在第一页提交的值来自 $ this-> request-> query
它进入 $ this-> params->命名,但它需要在 $ this-> request-> ;查询



我的分页部分来自视图文件:

 code>< div class =paging> 
<?php
$ this-> Paginator-> options(array('url'=> $ this-> request-> query));
echo $ this - > Paginator→> prev('<'。__('Previous'),array(),null,array('class'=>'prev disabled'));
echo $ this - > Paginator - >数字(array('separator'=>''));
echo $ this - > Paginator - > next(__('Next')。'>',array(),null,array('class'=>'next disabled'));
?>

打印第一页上的参数:

  [query] => Array 

[first_name] =>
[username] => an
[email] =>
[dob] =& $ b(
[year] =>
[month] =>
[day] =>


)$ b b

 >  [named] => Array 

[first_name] =>
[username] => an
[email] =>
[dob%5Byear%5D] => ;
[dob%5Bmonth%5D] =>
[dob%5Bday%5D] =>

[query] => Array

[/ admin / users / index / first_name:/ username:an / email:/ dob] => Array

[year] =>



< / div>


解决方案

我在View文件中添加了以下代码,事情工作正常。在所有页面中param值都来自request-> query

  $ url = $ this-> params ['url'] ; 

unset($ url ['url']);
if(isset($ this-> request-> data)&&!empty($ this-> request-> data)){
foreach($ this-> request-> data [$ model_name] as $ key => $ value)
$ url [$ key] = $ value;
}
$ get_var = http_build_query($ url);

$ arg1 = array();
$ arg2 = array();
//取命名的url
if(!empty($ this-> params ['named']))
$ arg1 = $ this-> params ['named'] ;

//传递参数
if(!empty($ this-> params ['pass']))
$ arg2 = $ this-& '通过'];

//合并命名和传递
$ args = array_merge($ arg1,$ arg2);

//添加变量
$ args [?] = $ get_var;
$ this-> Paginator-> options(array('url'=> $ args));

在Controller操作方法中,我添加了以下

  $ args = $ this-> params ['url']; 
unset($ args ['url']);
if(isset($ args ['submit']))
unset($ args ['submit']);
if(!empty($ this-> request-> data)){
foreach($ this-> data ['User'] as $ key => $ value)
$ args [$ key] = $ value;
} else {
foreach($ args as $ key => $ value)
$ this-> request-> data ['User'] [$ key] = $ value ;
}


Cakephp 2.0 Pagination issue. How to pass arguments in pagination link?

I passed the arguments like

 $this->Paginator->options(array('url' =>  $this->request->query));

but after 2 nd page its not working .

On first page submitted values are coming in $this->request->query but from second page its coming in $this->params->named but it needs to come in $this->request->query

My Pagination part from view file:

<div class="paging">
    <?php
    $this->Paginator->options(array('url' =>  $this->request->query));
        echo $this -> Paginator -> prev('< ' . __('Previous'), array(), null, array('class' => 'prev disabled'));
        echo $this -> Paginator -> numbers(array('separator' => ''));
        echo $this -> Paginator -> next(__('Next') . ' >', array(), null, array('class' => 'next disabled'));
    ?>

while printing params on first page :

[query] => Array
    (
        [first_name] => 
        [username] => an
        [email] => 
        [dob] => Array
            (
                [year] => 
                [month] => 
                [day] => 
            )

    )

while printing params on second page :

    [named] => Array
            (
                [first_name] => 
                [username] => an
                [email] => 
                [dob%5Byear%5D] => 
                [dob%5Bmonth%5D] => 
                [dob%5Bday%5D] => 
                )
[query] => Array
    (
        [/admin/users/index/first_name:/username:an/email:/dob] => Array
            (
                [year] => 
            )

    )
</div>

解决方案

I added the following code in View file and now every thing is working fine. in all pages param values are coming in request->query

$url = $this->params['url'];

    unset($url['url']);
    if(isset($this->request->data) && !empty($this->request->data)) {
        foreach($this->request->data[$model_name] as $key=>$value)
            $url[$key] = $value;
    }
    $get_var = http_build_query($url);

    $arg1 = array();
    $arg2 = array();
    //take the named url
    if(!empty($this->params['named']))
        $arg1 = $this->params['named'];

    //take the pass arguments
    if(!empty($this->params['pass']))
        $arg2 = $this->params['pass'];

    //merge named and pass
    $args = array_merge($arg1,$arg2);

    //add get variables
    $args["?"] = $get_var;
    $this->Paginator->options(array('url' =>  $args)); 

And in Controller action method I added the following

    $args = $this->params['url'];
    unset($args['url']);
    if(isset($args['submit'])) 
        unset($args['submit']);
    if(!empty($this->request->data)){
        foreach($this->data['User'] as $key=>$value)
            $args[$key] = $value;
    }else{
        foreach($args as $key=>$value)
            $this->request->data['User'][$key] = $value;
    }

这篇关于Cakephp 2.0分页问题。如何传递参数在分页链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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