PHP Classes

Using fFunction

Recommend this page to a friend!

      myPageDisplay  >  All threads  >  Using fFunction  >  (Un) Subscribe thread alerts  
Subject:Using fFunction
Summary:Array structure for fFunction
Messages:4
Author:Ken Joyce
Date:2007-03-01 21:07:13
Update:2007-03-03 12:38:59
 

  1. Using fFunction   Reply   Report abuse  
Picture of Ken Joyce Ken Joyce - 2007-03-01 21:07:13
Having satisfaction with the class.

The fFunction comment says "function to perform on db field, eg. function or array of functions"

Would you expand on the syntax for this, and how it works?

Can it pass parameters as well?

Thanks,

Ken

  2. Re: Using fFunction   Reply   Report abuse  
Picture of Peter Barkway Peter Barkway - 2007-03-02 14:01:28 - In reply to message 1 from Ken Joyce
Ken,

the fFunction element is designed to perform particular functions on the data that is returned by the db field specified with cField. The function can take the form of a simple PHP function, such as number_format or a more complicated ad-hoc function where arguments need to be passed (this is the array bit). The following to examples should hopefully demonstrate.

1. Simple argument.
array( 'cTitle' => "Contact Name",
'cField' => 'contact',
'cWidth' => '40%',
'cSort' => 0,
'cAlign' => 'left',
'fFunction' => 'ucfirst',
'fLink' => '',
'lTarget' => ''
),

In this example the it is the equivelant of saying ucfirst($row->contact) in that the fFunction (ucfirst) is performed on the returning data for the db field 'contact'.

2. Complex argument
array( 'cTitle' => "Address",
'cField' => 'county',
'cWidth' => '25%',
'cSort' => 1,
'cAlign' => 'left',
'fFunction' => array('addressFormat'=>array('address1',
'address2',
'town',
'county',
'postcode',
'country'
)
),
'fLink' => '',
'lTarget' => ''
),

This example performs a more complex function in that cField value will not actually be displayed. Instead, the value returned by fFunction function 'addressFormat' will be displayed. Because the 'addressFormat' function requires arguments to be passed it is done as an array, in this case made up of db fields.

The class will check to see if the values are db fields, if not it will take them literaly.

I hope this explanation helps. If not let me know.

Regards

Peter

  3. Re: Using fFunction   Reply   Report abuse  
Picture of Ken Joyce Ken Joyce - 2007-03-03 02:53:19 - In reply to message 2 from Peter Barkway
Thank you, Peter, just what I needed to know.

A nice, neat class which I can use - now that I have your reply.

Are the only columns which can be included those which come from the sql enquiry, or can other columns be included?

I am thinking of the possibility of making each row a form, including items such as checkboxes or select lists in the columns then using the action buttons to do something incorporating say the id value and values from other fields such as the checkbox.

If I play with what you have done I will probably work it out, but it's easier to ask you!

Ken

  4. Re: Using fFunction   Reply   Report abuse  
Picture of Peter Barkway Peter Barkway - 2007-03-03 12:38:59 - In reply to message 3 from Ken Joyce
Ken,

Unfortunately the answer is yes - they can only come from the SQL query. I do sometimes throw in a dummy field to allow for some manipulation, for example:

$sql = "SELECT log_hour,
SUM(IF(log_type = 'Searches', log_count, 0)) AS searches,
' ' AS spacer
FROM $this->tableName2
WHERE log_date = '$searchDate'
GROUP BY log_hour";

but I don't think this is what you are after.

I have been working on another class to help generate menu structures and have used javascript functions that manipulate the DOM to do what you are after. Take a look at http://www.baytree-cs.com/index.php?pid=151

If this is what you are after I will be uploading the code to phpclasses soon and you will be able to modify it to do what you want it to do. I just need to get all the documentation up to scratch before submitting it but hope to have that done sometime within the week.

Peter