How to build a file name with variables?

joachimliedtke 30 Nov, 2017
I want to give a file a unique name, that is easy identifiable, e.g. filename-{aid}.csv, where {aid} is the id when content is saved to the database. The read_dataXX function is working properly and all the values go to the file, so "aid" is known, but what do I have to do to make it part of the file name?

filename-{var:read_data4.Data4.aid}.csv


This returns only filename-.csv, but

filename-{var:read_data4.[n].Data4.aid}.csv


returns nutzertermin-["21"].csv. 21 is the correct aid, but I don't want the brackets and the quotes in the name. Any ideas?

TIA
Max_admin 04 Dec, 2017
Hi,

Please set the your "read data" "select type" to "First matching" in order to get a single record then use:
{var:read_data4.Data4.aid}


Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
joachimliedtke 05 Dec, 2017
Thanks for your advice. The filename is now as I wanted, but the CSV is now completely empty. I tried several settings myself, but no solution. The debugger shows, that the data is there in an array, but the data is not written to the file.

These were my prior settings for reading data:
Order fields = aid/desc
Select type = All matching records instead of First matching record
Paging for multiple results = Disabled
Page limit = 1
Offset = 0
Fields to retrieve = All needed fields were entered
Settings for writing CSV:
Data provider = {var:read_data4.[n].Data4}
Disabled header titles
Filename = nutzertermin-{var:read_data4.Data4.aid}.csv <- As told

So I have the choice, filled CSV and not the filename I want or the filename I want, but empty CSV.πŸ™‚

Perhaps I don't get the concept behind reading data and writing the file. So I need a little more assistance on this matter.

TIA
joachimliedtke 12 Dec, 2017
I found a solution, well more a dirty hack. Open / libraries / cegcore2 / admin / extensions / chronofc / functions / csv / csv_output.php and insert after line 56

$file_path = str_replace('[', '', $file_path);
$file_path = str_replace(']', '', $file_path);
$file_path = str_replace('"', '', $file_path);


So the special chars are removed from nutzertermin-{var:read_data4.[n].Data4.aid}.csv

Don't expect elegant code from me.πŸ˜€
Max_admin 27 Dec, 2017
Hi joachim,

Thank you for sharing the codeπŸ™‚

it depends on the syntax used, the file name shortcode should return a string, but the provider should return an array, otherwise there will be problems!

You can test nutzertermin-{var:read_data4.Data4.aid}.csv in a custom code action to check if it returns the correct filename value.

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.