Jump to:

1155 Posts in 2568 Topics by 408 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » SS_HTTPRequest could not be converted to int

Ask questions about upgrading SilverStripe to the latest version.

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

Page: 1
Go to End
Author Topic: 1178 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    SS_HTTPRequest could not be converted to int Link to this post

    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

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: SS_HTTPRequest could not be converted to int Link to this post

    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.

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: SS_HTTPRequest could not be converted to int Link to this post

    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

    1178 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.