Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Upgrading SilverStripe

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

SS_HTTPRequest could not be converted to int


Reply

3 Posts   1196 Views

Avatar
Garrett

5 October 2010 at 9:11am Community Member, 245 Posts

Hi,

I have used the code below hundreds of times in Silverstripe. Just trying to pass in a limit to a function to decide how many items to chow in the template:

public function News($limit=0) {
if($limit!=0)
return DataObject::get("NewsPage", "", 'Date DESC', "", $limit);
else
return DataObject::get("NewsPage", "", 'Date DESC', "", "");
}

Since I've been working in 2.4.1, I get the following error:

[Notice] Object of class SS_HTTPRequest could not be converted to int

On this line:

if($limit!=0)

WHY? What is wrong with this code?

Thanks,
Garrett

Avatar
simon_w

5 October 2010 at 9:17am Forum Moderator, 474 Posts

You're calling the method by using a URL. Something like http://your-site.com/page-name/News, which means a SS_HTTPRequest is passed as the argument. You could use something like

if(is_numeric($limit) && $limit != 0)

which should handle this better.

Avatar
Garrett

6 October 2010 at 3:29am Community Member, 245 Posts

Genius.

I never really "got" the URL "action" thing until now. I was clearly hoodwinked by having a page and a function with the same name. So I guess the function takes precedence....

//Garrett