17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 8693 Views |
-
Re: Get random object

2 September 2008 at 4:49pm
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.
-
Re: Get random object

2 September 2008 at 4:57pm
No idea. That's almost the exact code I have in use right now.
Cheers
Aaron -
Re: Get random object

2 September 2008 at 5:01pm
moloko_man, append ?isDev=1 to you URL to get the error message.
-
Re: Get random object

2 September 2008 at 5:08pm
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.phpuser_error(Bad class to singleton() - Products,256)
line 85 of Core.phpsingleton(Products)
line 1572 of DataObject.phpDataObject::get_one(Products,,,RAND())
line 18 of HomePage.phpHomePage_Controller->getRandomObject()
call_user_func_array(Array,Array)
line 404 of ViewableData.phpViewableData->XML_val(getRandomObject,,1)
line 12 of .cache.Applications.MAMP.htdocs.biomicro.com.tutorial.templates.Layout.HomePage.ssinclude(/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.phpSSViewer->process(HomePage_Controller)
line 189 of SSViewer.phpSSViewer->process(HomePage_Controller)
line 296 of Controller.phpController->defaultAction(index,Array)
line 267 of Controller.phpController->run(Array)
line 22 of ModelAsController.phpModelAsController->run(Array)
line 27 of RootURLController.phpRootURLController->run(Array)
line 104 of Director.phpDirector::direct(/)
line 158 of main.php -
Re: Get random object

2 September 2008 at 5:11pm
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.
-
Re: Get random object

2 September 2008 at 5:19pm Last edited: 2 September 2008 5:22pm
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?
-
Re: Get random object

2 September 2008 at 5:21pm
Product is the name of the class you're trying to get one of. Do you have a Product class?
| 8693 Views | ||
| Go to Top | Next > |


