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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

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

SS_HTTPRequest could not be converted to int


Go to End


3 Posts   2083 Views

Avatar
Garrett

Community Member, 245 Posts

5 October 2010 at 9:11am

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
(deleted)

Community Member, 473 Posts

5 October 2010 at 9:17am

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

Community Member, 245 Posts

6 October 2010 at 3:29am

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