TransWikia.com

How can I get field values for the sections that I created

Craft CMS Asked by Charles-Edouard Charles-Edouar on July 27, 2021

New to Craft CMS. We decided to make Craft headless and have an api fetch the data.

I have 5 (simple) sections that represent 5 pages and they all have some fields in them with some texts or images. So far so good.

Now, the cms is headless, so I added a controller to return the pages data (some texts and images). I used Entry::find()->section('homepage')->one(); It returns an Entry Object, but the field’s values are nowhere to be found.

Ex: In the cms, I have a hero field that contains a text and an image, but for the love of god I can’t get the values of them using the query builder…

When I print the result of the query, I see the field names in the Entry object, but they are all NULL. Yes, my homepage entry in the cms is filled with texts and images for those fields…

[_behaviors:yiibaseComponent:private] => Array
(
    [customFields] => craftbehaviorsCustomFieldBehavior Object
    (
        [hero] => 
        [titre] => 
        [description] => 
        [fullWidthCTA] =>    
        [...]             
    )
)

I also tried Entry::find()->section('homepage')->one()->getFieldValue('hero') but same problem…

If it’s not clear enough, just let me know and I’ll post an update in the morning.

Thank you.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP