Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Get random object

Our old forums are still available as a read-only archive.

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

Page: 1 2 3
Go to End
Author Topic: 9168 Views
  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    ok, I put the function in the right place and I'm calling it in the .ss page, but I'm getting this error:

    Error
    The website server has not been able to respond to your request.

    I'll keep checking things, just to make sure I didn't leave something out.

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: Get random object Link to this post

    No idea. That's almost the exact code I have in use right now.

    Cheers
    Aaron

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    hmmm, what did you put in your .ss page?

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Get random object Link to this post

    moloko_man, append ?isDev=1 to you URL to get the error message.

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    wow, lots of errors still a noob at this, but trying to figure it out.
    here is what I get:

    FATAL ERROR: Bad class to singleton() - Products
    At line 85 in /Applications/MAMP/htdocs/biomicro.com/sapphire/core/Core.php

    user_error(Bad class to singleton() - Products,256)
    line 85 of Core.php

    singleton(Products)
    line 1572 of DataObject.php

    DataObject::get_one(Products,,,RAND())
    line 18 of HomePage.php

    HomePage_Controller->getRandomObject()

    call_user_func_array(Array,Array)
    line 404 of ViewableData.php

    ViewableData->XML_val(getRandomObject,,1)
    line 12 of .cache.Applications.MAMP.htdocs.biomicro.com.tutorial.templates.Layout.HomePage.ss

    include(/private/var/folders/wO/wOacFITKFUaUHT-w02HAXk+++TI/-Tmp-/silverstripe-cache-Applications-MAMP-htdocs-biomicro.com/.cache.Applications.MAMP.htdocs.biomicro.com.tutorial.templates.Layout.HomePage.ss)
    line 197 of SSViewer.php

    SSViewer->process(HomePage_Controller)
    line 189 of SSViewer.php

    SSViewer->process(HomePage_Controller)
    line 296 of Controller.php

    Controller->defaultAction(index,Array)
    line 267 of Controller.php

    Controller->run(Array)
    line 22 of ModelAsController.php

    ModelAsController->run(Array)
    line 27 of RootURLController.php

    RootURLController->run(Array)
    line 104 of Director.php

    Director::direct(/)
    line 158 of main.php

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Get random object Link to this post

    This is because you're trying to get a singleton of products instead of Product. Use:

    function getRandomObject() {
    return DataObject::get_one('Product', null, false, 'RAND()');
    }

    instead.

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Get random object Link to this post

    even with that change I still get a whole list of errors. in the get_one() function, what is the first item referring to? i.e. get_one('Product', null, false, 'RAND()'); 'Product' should be the section?

    could it be that I have two sub levels to the Product page? I have the product page, then a page for each product and then pages for specs, publications, etc. should I just be sticking to one sub level?

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: Get random object Link to this post

    Product is the name of the class you're trying to get one of. Do you have a Product class?

    9168 Views
Page: 1 2 3
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.