Jump to content

Fatal error: Exception: Invalid type to Pageimages::remove(item)


RyanJ
 Share

Recommended Posts

If a page contains an image, I get no error. If a page does not contain an image I get the following. Fatal error: Exception: Invalid type to Pageimages::remove(item) message. Any suggestions is appreciated.

my code:

$first = $page->image->first;

if (count($page->image) > 1) {
   echo "<h4>$page->title</h4>";
  }
  foreach($page->image->remove($first) as $img) {

  if ($img) {
   echo "<img src='{$img->url}' />";
   }
  }
Link to comment
Share on other sites

I think your } on the third line isn't supposed to be there. The foreach is getting called every time. I think you might want something like this:

if (count($page->image) > 1) 
{
	$first = $page->image->first;
	echo "<h4>$page->title</h4>";
	foreach($page->image->remove($first) as $img) 
	{
		if ($img) 
		{
			echo "<img src='{$img->url}' />";
		}
	}
}
  • Like 3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...