Forums

apply a php function to more than one column

ataylor14 05 May, 2017
Dear all

First I want to say to the creators of connectivity v6 that - as I have been playing around with the demos - I came to appreciate that this is a great product! Fun to work with and interesting...It definitely fired up quite a few neurons in my brain!

Now my questions. I have two columns containing a UNIX timestamp. In the front end I want to display them as a date in the format say Y-m-d.

I managed to do this for each field in two ways.
The first: I created a function of type php on similar lines as in https://www.chronoengine.com/forums/posts/t102515/how-to-sum-two-or-more-collums-in-table-format.html

The second: I created an HTML view in which I used the same php code as the one I had in the php function to convert the UNIX datestamp into a date Y-m-d

However, to create 2 functions (or 2 HTML views) one for each field seems too much. Is there a way to define a php function that takes parameters? Can I pass the fields as a parameter to the php function? So then I would define it only once and use it multiple times on several columns.

I hope my explanations are clear🙂

Thank you
Kind regards
Amelia
Max_admin 08 May, 2017
Hi Amelia,

I'm glad you like the product!🙂

Unfortunately the feature you need does not exist yet, but its really important, so starting from the next update you will be able to pass variables to the functions and views when you call them, example:

{fn:php_function_name$myvar1=myvalue1&myvar2=myvalue2}


Then in the PHP function you can use:

$this->get("myvar1");


If you think the syntax should be improved or other features added then please do not hesitate to let me know.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Natalini 21 May, 2017
Hi Max,
I don't know if the actual version of CCv6 is ready for this, but if it is how can i pass variable on a colum view of a table?

I have many columns in my externalDB with date formatted unlike I need. So by now I create a PHP function for every field...

Now It'll be great to use a uniqe fn with variable like this: (fn:php1)
echo date("d/m/Y", strtotime($this->get("mydate")));

But in the view what can I write??
ddt.data:{fn:php1&mydate=?the date of this row and this column?}

Thanks a lot.
Marco
Max_admin 22 May, 2017
Hi Marco,

If you have the new update released about 10 hours ago, then you can create a php function, lets say "php1", then call it from the table columns like this:

{fn:php1$mydate=(view:table_view_name.row.Model.field_name)}


Now in the PHP function, you can use this code:

echo date("d/m/Y", strtotime($this->get("mydate")));


So its only 1 function now to do the processing, but the parameter value you pass changes.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Natalini 22 May, 2017
Ciao Max,
it seems that the variable $mydate=(view.etc...) isn't passed to the function...
The result on my table is 01/01/1970 for all the rows.
I have also try with
$mydate=(var:read_fn_name.row.Model.field_name)
but nothing change.

with {debug:} I can't find anything useful to understand.

thanks
Marco
Natalini 22 May, 2017
Answer
1 Likes
Hey,hey..forgive me.
I found the syntax error..

{fn:php1$mydate=(var:table_view_name.row.Model.field_name)}


The variable needs "var" not "view".. and then the table_view_name

It's all ok, and It's a very great upgrade.

goodnight
Marco
Max_admin 24 May, 2017
Hi Marco,

Good catch, it was a mistake in my code!🙂

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.