We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47401
    • 295 Posts
    I am trying to send data to a chunk using the api. the snippet i have so far is:

    <?php
    if(isset($_GET['loanamount'])) {
    $la = $_GET['loanamount'];
    } else {
    $la = 10000;
    }
    if(isset($_GET['month'])) {
    $m = $_GET['month'];
    } else {
    $m = 12;
    }
    
    
    $url = "http://some-website.com/api/$la/$m";
    //  Initiate curl
    $ch = curl_init();
    // Disable SSL verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Set the url
    curl_setopt($ch, CURLOPT_URL,$url);
    // Execute
    $result=curl_exec($ch);
    // Closing
    curl_close($ch);
    
    //var_dump(json_decode($result, true));
    $data = json_decode($result, true);
    echo "<pre>";
    print_r($data);
    echo "</pre>";
    
    // cycle through data call chunk get-table-row-data and insert properties into chunk.
    if(!empty($data)) { // checks of the data exists
    
    for($i=0;$i<=count($data);$i++) { // loops through array
    
    $properties = $data[$i]; // array to variable (still an array)
    
    echo $chunk = $modx->getObject('modChunk', array('name'=>'get-table-row-data'));
    
    // this is the bit im stuck with, sending the $properties variable to the chunk and outputting it to the screen
    
    } // end for loop
    
    
    } // end if statement


    im not too sure how to retreive the chunk in the loop, whilst looping the array, sending the data to the chunk then outputting to the screen.

    has anybody else done this in any of their existing projects?

    Thanks

    This question has been answered by comp_nerd26. See the first response.

      • 47401
      • 295 Posts
      ive figured out how to retreive the data, its just a case of now modifying the data before it outputs to the screen that im not familiar with.

      line 39 variable changed from $properties to $params
      instead of line 41 above i replaced it with the below code:

      $chunk=$modx->parseChunk('get-table-row-data', $params, '[+', '+]');
      • discuss.answer
        • 47401
        • 295 Posts
        ok guys i think ive sussed it. $params must be a multidimensional array, keys containing names. in the chunk to retreive data from the array you simply use
        [+array_key+]

        as you specified in the line after $params. I changed this to [[+ and ]]+ just to make things a bit more clear. other than that this is now resolved. could help somebody else out whos having the same problems as i was wink