Best Way To Familiarize With DF

Anyone have any suggested methods for really familiarizing oneself with the scripting docs? Specifically, the PHP scripts.

I know the engineers are working on the documentation for DF 2.0, but I’m just wondering where the best place to learn the methods, functions, etc… that I can call within a script. Where should I look within the install directory to gain more insight into the available methods?

For example, I am trying to call something like “platform.api.get()” using PHP, but it doesn’t seem to work so I’m trying to figure out how to use the following code from the PHP scripting example to create an internal GET request from within a custom script to download a file:

DreamFactory\Core\Utility\ServiceHandler::handleRequest(
‘POST’,
‘push’,
‘topic/arn:aws:sns:us-east-1:xxxxxx:new_todo’,
[],
[
“Message” => “A new Todo named “.$payload[‘name’].” was just created.”,
“Subject” => “New Todo Created”,
]
);
(obviously I need to modify that code)

I’m trying to basically make a custom pre_process script for my file storage service which changes the inbound URL request. It seems the pre/post processing server scripts do not fire for some reason currently. Someone else reported this issue, but I can’t find the link ATM. Like the user who reported the issue, I’m trying to take an inbound folder request and internally modify the link to their folder.

Unlike with JavaScript we don’t have all those classes pre-built.
Here is a sample PHP script for interacting with the API that one of the engineers sent me. Hopefully it’s enough to get you going.

use \DreamFactory\Core\Utility\ServiceHandler;
use \DreamFactory\Core\Enums\DataFormats;

$verb = \Request::method();
$service = \Request::input('service');
$resource = \Request::input('resource');
$urlQuery = \Request::query();
$postedPayload = \Request::json()->all();
$format = DataFormats::JSON;
$headers = \Request::header();

// uncomment for debugging
//return [
//    'verb' => $verb,
//    'service' => $service,
//    'resource' => $resource,
//    'query' => $urlQuery,
//    'payload' => $postedPayload,
//    'format' => $format,
//    'headers' => $headers
//];

return ServiceHandler::handleRequest($verb, $service, $resource, $urlQuery, $postedPayload, $format, $headers);

Just to remind that the documentation will be released in dec, 20.

=D

Thanks @formerstaff and @kimpatro, those pieces of information will both be very helpful.

Looking forward to a Dec. 20 docs release!

1 Like

@formerstaff is there a way to access the user object with php? like user.id?

EDIT:
Got it, ya’ll. To access a user’s info in a custom script do this:

$userInfo = ServiceHandler::handleRequest(‘GET’,‘user’,‘session’,[ ],[ ]);

Follows the paradigm Drew left us above.

‘session’ can be replaced with whatever other resource (like ‘custom’, or ‘profile’, or left blank).

Now trying to figure out how to access a user’s custom lookup key…

EDIT 2: Found out how to get a user’s custom lookup key:

/system/user/4?related=user_lookup_by_user_id

system user and related are the answer here - i think

That look right, to the best of my knowledge. I’m still getting up to speed on the PHP scripting.

Hey Kim, any idea when the documentation related to PHP scripting will be up on the website. There are few examples on the documentation but that isn’t fully useful if we have to write a complex PHP script.

Hi,

I don’t know what you want to do, but there’s this documentation: https://wiki.dreamfactory.com/DreamFactory/Tutorials#PHP

Maybe @formerstaff could give you more information.

No updates right now. The dev team is working on getting 2.1 out the door.

This is helpful. I’m trying to use this to retrieve all records from a table on a post post using:
$csvInfo = DreamFactory\Core\Utility\ServiceHandler::handleRequest('GET','mysql','_table/saa-recipients'); var_dump($csvInfo);

It’s only returning the record I just submitted via POST and not all records. This is sort of useless as my post data is available as \Request::json()->all();

PHP Scripting tutorials have been added/updated since this topic started. https://wiki.dreamfactory.com/DreamFactory/Tutorials#Scripting