Jump to content

Get a predefined values for my package


Recommended Posts

Hello,

please I try to create a provisioning module, and i want to know how can i get predefined values for each package a create using my module this is my code 

function app_ConfigOptions($params){
    return [
        // Text field powered by the Loader function
        'Package' => [
            'Type' => 'text',
            'Size' => '25',
            'Loader' => 'centrix_LoaderFunction',
            'SimpleMode' => true
        ]
    ];
}

function app_LoaderFunction(){
  // Make a call to the remote API endpoint
    $ch = curl_init('http://myapp.club/api.php');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);

    // Check for any curl errors or an empty response
    if (curl_error($ch)) {
        throw new Exception('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch));
    } elseif (empty($response)) {
        throw new Exception('Empty response');
    }

    // We're done with curl so we can release the resource now
    curl_close($ch);

    // Attempt to decode the response
    $packageNames = json_decode($response, true);

    // Check to make sure valid json was returned
    if (is_null($packageNames)) {
        throw new Exception('Invalid response format');
    }

    // Format the list of values for display
    // ['value' => 'Display Label']
    $list = [];
    foreach ($packageNames as $packageName) {
        $list[$packageName] = ucfirst($packageName);
    }

    return $list;
}

the idea is I want to get predefined fields for each package I create

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated