Giter VIP home page Giter VIP logo

Comments (6)

gregvarghese avatar gregvarghese commented on June 5, 2024 1

Thanks, @bakerkretzmar. That was the issue and I feel like a dunce. I misread my own code and thought the ,true in the file_get was part of the json_decode. Thanks again and sorry for wasting your time but I sincerely appreciate the assist!

from jigsaw.

bakerkretzmar avatar bakerkretzmar commented on June 5, 2024

How are you fetching $projects->data and how exactly are you accessing the data in your template? Can you include the code where you're trying to access ->value and getting that error? If possible can you also include the complete code snippets you're using to send data to Ray, and screenshots of what's coming through? The formatting of the Ray dump you included makes it hard to understand exactly what it is.

Off the top of my head this looks like it could just be that you're calling json_decode(...) instead of json_decode(..., true) somewhere, and so your data is coming back as PHP objects instead of nested arrays. Or maybe the opposite, and it's an array and you need to do $stat['value'] instead of $stat->value.

from jigsaw.

gregvarghese avatar gregvarghese commented on June 5, 2024

Hi @bakerkretzmar ,

Thanks for the quick reply.

Here's the code from config.php where I pull the remote API. It's a secure URL with secure auth token so I could not include it but it does return the JSON above.

'projectstats' => [
           'extends' => '_layouts.project',
           'items' => function ($config) {

               $context = stream_context_create(array(
                   'http' => array(
                       'header'  => "X-AUTH-TOKEN: $token"
                   )
               ));

               $projects = json_decode(file_get_contents('secure_url', true, $context));

               $collection = collect($projects->data)->map(function ($project) {

                   return [
                       'title' => $project->title,
                       'stats' => $project->stats,
                       'path' => '{collection}/{name}',
                   ];
               });

               ray($collection)->label('Project with Stats');
               return $collection;
           }
       ],

In the page, here's how I'm viewing the page object with Ray:

@php(ray($page)->label('Project Page'))

Displaying it in the page is just stacking it in a div right now:

                        <div class="stats">
                            @php(ray($stats)->label('Stats Count'))
                            @foreach($stats as $stat)
                                <p>{{ $stat->value }}</p>
                                <p>{{ $stat->label }}</p>
                            @endforeach
                         </div>

Screenshot of Ray for both the collection from config and page variable (sensitive info was blacked out) showing that stats are null on the page object:

ray-684

I checked another collection with a nested array of image urls and confirmed it's exhibiting the same behavior. I hadn't created the page last night when I submitted the ticket which is why I'm mentioning it now.

Please let me know if I can provide any additional information to help troubleshoot.

from jigsaw.

gregvarghese avatar gregvarghese commented on June 5, 2024

Hi @bakerkretzmar, just wanted to follow up on this issue. Do you need any more information from me?

from jigsaw.

bakerkretzmar avatar bakerkretzmar commented on June 5, 2024

@gregvarghese looks like this is because Symfony's YAML component doesn't dump objects by default, it needs to be passed the Yaml::DUMP_OBJECT_AS_MAP flag. I'm not sure how risky adding that to Jigsaw core is but we'll look into it.

For now if you set json_decode()'s $associative parameter to true (json_decode(..., true)) all your data will come back as arrays and your code should work fine.

from jigsaw.

bakerkretzmar avatar bakerkretzmar commented on June 5, 2024

No problem, and definitely not a waste of time! The YAML object dumping thing is something we should look at more closely so I'm glad you made me find it 😄

from jigsaw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.