Jump to content

Get latest item of images array


Manaus
 Share

Recommended Posts

Hello, 

I added a crop image field in the user template, and set the field to accepting 1 file only. I upload the image via the front end using these values:

     $a->setMaxFiles(1);
     $a->setOverwrite(true); 

Now, if I upload an image via the back end or the front end, the image field keeps many images. 

This resolves in a code trouble: if I try to print $page->createdUser->image->getThumb('micro') I get a string: the first image, but I need the last one. Btw printing $user->image I get an array, but it’s not what I need. Tried of course $page->createdUser->image->last()->getThumb('micro'), but returns an error "Pageimage::last does not exist or is not callable in this context"

Thanks for any suggestion...!

Link to comment
Share on other sites

I think you might need to do something like this:

$users->get($page->createdUser->name)->image->last->getThumb('micro');

You need to get the name of the createdUser of the current page and get that user's fields from $users.

As for the issue of keeping multiple images - those settings won't work on the front end - you need to delete all existing images before uploading. See this post from Ryan: http://processwire.com/talk/topic/4267-creating-new-page-in-combination-with-a-file-upload/?p=41876

Hope that helps.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...