Search

I've been recently engrossing myself with the Symphony system and, so far, I love it! Much better than the framework I was previously working with. I have run into a small snafu, however.

I'm trying to figure out how an Event can query a Datasource. That is to say, I'd like my Event to, upon triggering, request a specific and dynamic single Section entry, returning a result set as, say, an associative PHP array. This may sound like reinventing the Datasource as an Event, but I need to do some manipulations in PHP outside the scope of XSL.

Specifically, I have a Files section which stores metadata on an uploaded file (like a PDF or such). My Event is like the Force Download event, but I need access to the user-editable metadata stored in the section. I want to be able to dynamically set the filename of the requested document via PHP headers so that an Author can upload ex. file.pdf, but through the interface name it "Important Document," and when the file is downloaded via the frontend, it comes down as "Important Document.pdf."

I know how to do all the force downloading and dynamic naming through PHP, I just don't know how to get the event to query the Datasource to actually get that data.

Is this possible?

I know how to do all the force downloading and dynamic naming through PHP, I just don’t know how to get the event to query the Datasource to actually get that data.

You could just as easily add your force-download PHP to a Data Source instead. You can customise the Data Source’s grab() function and you’ll get the XML you need in the $result variable. The variable is a proprietary XMLElement but you can convert it to a string and load into a simplexml or DomDocument to parse:

$result->generate();

You could keep everything in an Event but Events by design all execute before Data Sources so you can’t make an event depend on the output of a DS. You could use something like the SymQL extension in the Event to query your section (which will return an associative array if you choose) but customising the Data Source sounds like the quickest route.

Thanks for the reply!

I believe I was unclear. I don't want the force-download to depend on the output of a DS. My event detects the presence of a GET variable and then downloads the file. I'm really horrible at explaining, so bear with me.

I have an entry in my "Documents" section that contains metadata for a PDF and the path to the uploaded file. On the frontend, when a user goes to /documents/my-file/, they see a nice printout of relevant metadata and a download button. That button links to /documents/my-file/?download which is where the Event springs up and forces the download. This is all well and good.

BUT, the downloaded file retains the filename it was uploaded with. Many files get uploaded by Authors with non-descriptive names like download249374-(1).pdf. The name of the file as it appears on the frontend is editable, and I want to use that single piece of info stored in the Entry.

I'm very new to Symphony, but wouldn't editing the grab() in my DS cause the file to be force-downloaded every time that DS is used, thus breaking the ability to output metadata?

don’t want the force-download to depend on the output of a DS

But you do… the force download depends on one of the field values in the DS.

The simplest way would be to pass the string in the download link itself.

/myfile/?download=myfilenamehere

Or you could put a conditional in the grab() function that looks for $_GET[‘download’] and forces the download, so that you font get a download on every page load.

As Nick said, you can’t query a data source in an event. But you can query your db directly. Just use the built-in php mysql functions to get your desired associative array.

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