Search the Community
Showing results for tags 'getRandom'.
Found 2 results
Hi all! having some trouble working with the getRandom - or actually, getting it to work another way. I'm currently selecting a random image from an imageArray by using the getRandom function. Now I want to know which image it picked though, so I thought of using php's own rand() function this way: rand(0, $arrayTitle->count()); Works like a blast, until it hit the first image at $arrayTitle(0)... I get the following error: Error: Uncaught Error: Method name must be a string in /Users/JCN/Sites/ffa/wire/core/WireArray.php:1648 Stack trace: #0 /Users/JCN/Sites/ffa/site/templates/head.inc(12): WireArray->__invoke(0) #1 /Users/JCN/Sites/ffa/site/templates/home.php(1): include_once('/Users/JCN/Site...') #2 /Users/JCN/Sites/ffa/wire/core/TemplateFile.php(182): require('/Users/JCN/Site...') #3 /Users/JCN/Sites/ffa/wire/core/Wire.php(398): TemplateFile->___render() #4 /Users/JCN/Sites/ffa/wire/core/Wire.php(333): Wire->runHooks('render', Array) #5 /Users/JCN/Sites/ffa/wire/modules/PageRender.module(422): Wire->__call('render', Array) #6 /Users/JCN/Sites/ffa/wire/core/Wire.php(398): PageRender->___renderPage(Object(HookEvent)) #7 /Users/JCN/Sites/ffa/wire/core/Wire.php(333): Wire->runHooks('renderPage', Array) #8 /Users/JCN/Sites/ffa/wire/core/Wire.php(459): Wire->__call('renderPage', Array) #9 /Users/JCN/Sites/ffa/wire/core/Wire.php(333): Wire->runHooks('render', Array) #10 /Users/JCN/Sites/ffa/wire/modules/Process/ProcessPageView.module(187) (line 1648 of /Users/JCN/Sites/ffa/wire/core/WireArray.php) ...all other images work fine though. Is this something I can fix in the .htaccess? And how come I've never had this before, in other projects? Love to hear your take on things... cheers!
So I tried using $page->repeater->getRandom() in some template code but it didn't seem to work. Should this work? If not, what is the recommended way of working with a single, randomly-chosen repeater item? Thanks!