Jump to content

API inconsistency with images


mindplay.dk
 Share

Recommended Posts

I have a Template that has a field with a list of images.

To my surprise, the image list returns two different things when accessing the images in two different ways:

<?php

var_dump($page->images->first()); // => Pageimage

var_dump($page->images[0]); // => Page 

Is this deliberate? It seems really inconsistent and, well, weird...

Link to comment
Share on other sites

WireArray implements PHP's ArrayAccess interface, so actually the something like $images[0] ideally would work. The reason for the inconsistent behavior is that images are indexed by filename, not by number. So $images['filename.jpg'] would be the actual ArrayAccess implementation. However, I think I could find a way to make it work by re-implementing the offsetGet() method in the Pagefiles and having it do a slice() to return a specific index. Thanks for reporting it! 

  • Like 2
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

  • Recently Browsing   0 members

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