Jump to content

Problem with retrieve value of a field FileType


abmcr
 Share

Recommended Posts

I have a field FileType named allegato into a repeater named documenti

5a721aba6ea3d_Schermata2018-01-31alle20_36_11.png.86db9a6e139b5c94d18c9677d096164b.png

I want to retrieve the value of the field allegato for all pages for creating a custom field module;
Into the module i have this code
 

foreach($output->documenti as $item) {
              echo "PRINT ALLEGATO";
              var_dump($item->allegato);
              echo "PRINT ALLEGATO -> count"; //this line echo the count as 1
              var_dump($item->allegato->count);
              echo "PRINT ALLEGATO -> items"; /(/this line get NULL.... WHY?
              var_dump($item->allegato->items);
              echo "PRINT ALLEGATO -> url";
              var_dump($item->allegato->url); // this line get me the url ... without the name of the file ????
              echo "PRINT ALLEGATO -> description";
              var_dump($item->allegato->description); //this line get me null though the value exist in the table (see image below)

The result is 

5a721c037019c_Schermata2018-01-31alle20_32_14.thumb.png.9c9b0dcaa9f03ebf2b25790d2164140a.png

 

where i show only one row (id 2003). Why i am not able to retrieve the value of $object->items??

And why $item->allegato->url show a partials url of the attachment and $item->allegato->description print null???

 

the same code into a single template work fine and output the correct values :huh:

Thank you in advance

Link to comment
Share on other sites

File fields are an array (unless you set maxFiles to 1), so you need to either foreach or first(), last() or eq(n) to get a specific file.

$item->allegato->first()->url;

There is no "items" property, hence the NULL.

  • Like 1
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...