Roych Posted July 2, 2018 Posted July 2, 2018 Hello, What is wrong here, Im getting an error. It works but tracy shows error on first line. <?php foreach($pages->get('/home/')->ozadje_strani as $bck): ?> <?php $image = $bck->bgimage->first(); ?> <img src="<?=$image->url; ?>" alt="<?=$image->description; ?>" /> <?php endforeach; ?> PHP Warning: Invalid argument supplied for foreach() ... Thank you R
Tom. Posted July 2, 2018 Posted July 2, 2018 Looks fine to me. I wouldn't worry about it if it's working. If you wanted to take the $pages->get('/home/')->ozadje_strani and put it in a variable that might fix it, but I'm not sure because it looks fine. 1
adrian Posted July 2, 2018 Posted July 2, 2018 I don't really understand why it's working at all - '/home/' is not the path for the home page, it's '/' - try that and things should work without the error. 1
Tom. Posted July 2, 2018 Posted July 2, 2018 @adrian I guess if it's working, he must have a page called Home? Maybe he has a splash screen before hand. Strange one. 2
adrian Posted July 2, 2018 Posted July 2, 2018 13 minutes ago, Tom. said: @adrian I guess if it's working, he must have a page called Home? Maybe he has a splash screen before hand. Strong one. Yeah, I guess you must be right. Maybe the ozadje_strani image field is set to return a single image which is why it can't be foreach'd? Actually, I guess it's a repeater field and bgimage is the image field - I don't know ? 2
Soma Posted July 2, 2018 Posted July 2, 2018 Not an error only a warning saying theres nothing to foreach. 3
dragan Posted July 2, 2018 Posted July 2, 2018 4 hours ago, Roych said: $image = $bck->bgimage->first(); You should always make sure you actually do have an image (except when it's a required field). Do an if() first, maybe the fields are empty? 2
Roych Posted July 2, 2018 Author Posted July 2, 2018 thanks for answers, I got it. It was a repeater, and had no image in it. I somehow made two of the same repeater field and somehow lost one which had no image in it. I deleted the field and it's fine now. Thank you all R 1
szabesz Posted July 18, 2018 Posted July 18, 2018 On 7/2/2018 at 6:53 PM, dragan said: except when it's a required field What if that required image one day becomes non-required? Usually I try not to rely on such settings.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now