1

i have endpoint: 'news/<slug:{slug}>.json' i print out EntryModel-Class in transformer function and it doesn´t seem to contain any photos like how it is described in Element Api example loop at the bottom of docs. i need to return all images and their locations as json for specific entry. any ideas?

'news/<slug:{slug}>.json' => function($slug) {

        return [

            'criteria' => [
                'section' => 'news',
                'slug' => $slug

            ],
            'transformer' => function(EntryModel $entry) {


                print_r($entry);

                //doesnt work --->
                // $photos = [];
                // foreach ($entry->photos as $photo) {
                //     $photos[] = $photo->url;
                // }
                //<----- doesnt work

                return [
                    'locale' => $entry->locale,
                    'slug' => $entry->slug,
                    'status' => $entry->status,
                    'title' => $entry->title,
                    'url' => $entry->url,
                    'uri' => $entry->uri,

                    'id' => $entry->id,
                    'heading' => $entry->heading,
                    'subheading' => $entry->subheading,

                    'linkUrl' => $entry->linkUrl,
                    'postDate' => $entry->postDate,

                    'children' => $entry->children,
                    'author' => $entry->author,
                    'link' => $entry->link,
                    'next' => $entry->next,
                    'parent' => $entry->parent,
                    'section' => $entry->section,
                    'type' => $entry->type,
                    'ancestors' => $entry->ancestors,
                    'body' => $entry->body,
                    'articleBody' => $entry->articleBody,
                    'featuredImage' => $entry->featuredImage,
                    'backgroundColor' => $entry->backgroundColor,
                    'serviceBody' => $entry->serviceBody,
                    'featuredThumb'=>$entry->featuredThumb,
                    'heroImage'=>$entry->heroImage,
                    'indexHeading'=>$entry->indexHeading,
                    'shortDescription'=>$entry->shortDescription,
                    'root'=>$entry->root
                    // 'photos' => $photos    <- i need image locations related to an entry
                    //'fields' => $entry->fields
                    // 'caption' => $entry->caption
                    // 'shortDescription'=> $entry->shortDescription,
                    // 'elementId' => $entry->elementId,


                ];
            },


        ];
    }

nothing under postDate seems to return anything....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.