1043 Posts in 379 Topics by 373 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1006 Views |
-
SS_HTTPRequest could not be converted to int

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 -
Re: SS_HTTPRequest could not be converted to int

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.
-
Re: SS_HTTPRequest could not be converted to int

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
| 1006 Views | ||
|
Page:
1
|
Go to Top |

