Jump to content

Recommended Posts

Posted

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...!

Posted

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
  • 3 weeks later...
Posted

Thanks Adrian.

I can't find last in the documentation, just last() (which is behaving differently, as it seems)

Any hint where I can look?

Thanks!

Posted

Manaus - my mistake, it should be last(). Please let us know what happens when you try:

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

They are the same. Like with first, child or children. Both version can be used. They're for convenience.

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
  • Recently Browsing   0 members

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