Search

I'm using a Remote Datasource to retrieve data from a third-party service. The remote URL is a PHP file in my workspace that queries the third-party service, massages the data a bit, and then spits out some JSON. That part's working fine.

The tricky part is getting the Remote Datasource to play nicely with my Section Datasources. I need the Remote DS to both read and write from the parameter pool and I can't work out how to do either.

Problem 1: Reading. The Remote DS needs certain settings that are stored in a Symphony Section. How do I pass values from a Section DS into a Remote DS? I tried adding them to the remote url as query parameters but it didn't seem to affect the Datasource dependencies. So I couldn't guarantee that the Datasources would be executed in the necessary order.

Problem 2: Writing. Basically I want output parameters for my Remote DS (for Datasource chaining purposes). How is this done? I've seen people suggest the Parametrisator but I'd prefer not use another extension. Is the only other option to write a custom Datasource and access the param pool programatically? If so, are there docs/examples of how to do that?

1) This sounds like a bug on the Remote DS, I'll take a look 2) Won't be possible out of the box, Remote DS can't write to the param pool at the moment

  1. I've had a fork of this running somewhere. Probably not exactly remote datasource but I can probably look at porting that to it. Would that be fine with you Brendan?

Remote DS can't write to the param pool at the moment

Thanks for the reply, Brendo. What are my options for getting the remote data into the param pool then? A custom Datasource? I read your introduction to Providers but couldn't find the example Github extension that it referred to. How about extending the RemoteDatasource class as it already has most of the functionality I need?

@gunglien, yeah that'd be great!

@pauldice, a Custom Datasource is an option yes. You could extend the Remote DS for this one scenario. @michael-e actually wrote recently a quick extension that shows how you can add things to the parameter pool.

I'm guessing you going to use XPath over the result to get the data to introduce into the parameter pool?

I'm guessing you going to use XPath over the result to get the data to introduce into the parameter pool?

Exactly. I wasn't aware of the frontendParamsResolve delegate though. I was planning to override the DS execute method, have it call the base implementation and then add the required params to the param_pool argument. Will that work?

Yes, and provided the dependencies are set correctly, it should be executed in order so the following datasources can access those values. Let me know how you go!

I ended up doing this a different way. Querying the third-party service can sometimes take several seconds and I didn't want to risk a performance hit on my site.

Instead of querying the service on page load I'm using an XML Importer to pull the remote data into a Symphony Section. With the data in Symphony I can use an ordinary DS to query it and generate the required output parameters. A cron job runs the importer every day to keep the data refreshed.

My PHP file retrieves the settings it needs to access the third-party service directly from the database. I already had some code that bootstraps Symphony and reads from/writes to Sections so I just reused that.

Importing is a better solution than a Remote Datasource in this particular case. Having the data in Symphony is more flexible and I don't need to worry about third-party response times.

I agree, that's a great solution and now you have a local cache of the data, and as you mentioned, you are now able to repurpose the information however you like!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details