开发者

Paginator::url giving different results than Paginator::link

I am using CakePHP 1.3, according to the docs the url() method:

returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)

This is what I need it for, JS. However if my current page's URL is:

/admin/orders/index/page:1/to:2011-08-16

and I put this on my page:

echo $this->Paginator->url(array('from'=>'FROM_PLACE_HOLDER'));
echo $this->Paginator->link('test',array('from'=>'FROM_PLACE_HOLDER'));

The results are:

/admin/orders/index/page:1/from:FROM_PLACE_HOLDER
<a href="/admin/orders/index/page:1/to:2011-08-16/from:FROM_PLACE_HOLDER">test</a>

If you noticed, the link() method maintains the to param while the url() method r开发者_高级运维esets it.

The strange part is I looked at the source for the link() method and it calls the url() method to get its URL. So something doesn't seem right.

Anyone know whats going on?


In the cake core code, it doesn't return directly from url(). I don't know the core code well enough, but I'd guess Paginator->link maintains all the non-paginator named parameters, while Paginator->url doesn't.

If you want url() to do the same, use

$this->Paginator->url(array_merge($this->params['named'], array('from'=>'FROM_PLACE_HOLDER')));

or $this->passedArgs to preserve all args.


If all else fails I can use the link() method and extract the URL from it like this:

$url = preg_replace(
    '/.*href="([^"]+)".*/', 
    "$1", 
    $this->Paginator->link('test',array('from'=>'FROM_PLACE_HOLDER'))
);

Seems pretty dirty to have to result to something like this though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜