Jump to content

Pagination and urlSegments issue


jtborger
 Share

Recommended Posts

Hi,

I have a problem getting pagination working with urlSegments. I read the docs and the forum, and another issue comes up with sort of the same thing. The problem there was that baseUrl got set by options and was left empty, while in the code below, the baseUrl is first set by the module manager (or something deep down..)

Anyhow, the problem is: my urlSegments wont get rendered in the link. I have the template setup correctly and the strange thing is, only the first part of the urlSegments shows up. Strange eh?

All the others are added via $queryString I think because I added them to $input->whitelist();

But I'm not sure if this is necessary.

Is it correct that normally, it would work out of the box because the urlSegments are part of the baseUrl?

And, if I read the code in MarkupPageArray.module line 146, where the baseUrl is set by default, I read:

if(empty($options['baseUrl'])) $pager->setBaseUrl($this->page->url . ($this->page->urlSegment ? $this->page->urlSegment . '/' : '')); 

This seems wrong and the reason only the first urlSegment gets added. Or, should $page->urlSegment contain all segments? And if it doesn't what could be the problem?

(btw: maxUrlSegments=4, default)

Link to comment
Share on other sites

I looked at where $page->urlSegment gets retrieved, and I think for the pageNav functionality it should be done different.

it reads: (Page.php, line 545)

case 'urlSegment':
		$value = $this->fuel('input')->urlSegment1; // deprecated, but kept for backwards compatibility
		break;

Since it says deprecated, I made a modification to markupPageArray.module line 146:

if(empty($options['baseUrl'])) $pager->setBaseUrl($this->page->url . ( count($this->input->urlSegments)>0 ? '/'.implode($this->input->urlSegments,"/") . '/' : ''));

Replacing $this->page->urlSegment to $this->input->urlSegments, which seems more proper to me.

Should I file a bug report via Github and fork and make a pull request Ryan, or what is the best way to fix this? Or am I just messing things up by thinking this is the error while its not? :)

  • Like 1
Link to comment
Share on other sites

Thanks jtborger, that makes sense to me. I'm updating it to this:

if(empty($options['baseUrl'])) {
  $baseUrl = $this->page->url;
  $urlSegmentStr = $this->input->urlSegmentStr; 
  if(strlen($urlSegmentStr)) $baseUrl = rtrim($baseUrl, '/') . "/$urlSegmentStr/";
  $pager->setBaseUrl($baseUrl); 
}
Link to comment
Share on other sites

Ah, I didn't know there was an $urlSegmentStr but that seems the right one to use indeed.

It's a pretty recent addition. I think it's in 2.3 stable. But if not, it's the same thing as implode('/', $input->urlSegments); 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...