3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 270 Views |
-
Forcing getRange to work

9 November 2011 at 10:17am
I feel so noobish for posting this. I've been unable to force getRange to work! It displays more posts than I want.
public function getCombinedNews($limit) {
$name = $this->Title;
$entries = DataObject::get("BlogEntry", "Tags LIKE '%{$name}%'");
$articles = $this->Articles();
$articles->merge($entries);
$articles->sort('Created', 'DESC');
if(isset($limit)) {
$articles->getRange(0,$limit);
}
return $articles;
} -
Re: Forcing getRange to work

9 November 2011 at 10:48am
It returns the range as a new DataObjectSet so it needs to be
$articles = $articles->getRange(0,$limit);
-
Re: Forcing getRange to work

9 November 2011 at 11:16am
Thanks for the tip! Unfortunately, that didn't work. To make sure it wasn't the if(isset()) part, I commented it out so that the limit would get applied regardless. It returns no objects at all now!
-
Re: Forcing getRange to work

9 November 2011 at 11:39am
Then I would be checking exactly what you're feeding the function. getRange is just
public function getRange($offset, $length) {
$set = array_slice($this->items, (int)$offset, (int)$length);
return new DataObjectSet($set);
}As you can see it's just array_slice() with one variable for where to start and one for how many to grab. Likely your $limit variable is either 0 or something else that gets turned into 0 by the int cast. Also since your function definition requires that $limit is sent to the function your isset will always return true.
| 270 Views | ||
|
Page:
1
|
Go to Top |


