String Manipulation before putting the data into mySQL

Archived from the Xataface Users forum.

chichi — Thu Jul 15, 2010 12:36 am

Hello, I would like to make a String Manipulation with PHP before putting the data into mySQL, is there an action before to use function for this? let me know.

I will use some of these functions of php:
nl2br()
strtolower()
etc.

chichi


shannah — Tue Jul 20, 2010 9:59 am

What do you mean by string manipulation? PHP is a full-fledged programming language that allows you to manipulate strings any any way you can imagine. E.g. check out this page for a list of PHP’s string functions:

http://php.net/manual/en/ref.strings.php


chichi — Wed Jul 21, 2010 7:37 am

Thanks for the info, i have done string manipulations before but dont know how to use (call/trigger) them in xataface befor saving the string to the database.


shannah — Wed Jul 21, 2010 10:28 am

You can make these transformations in the beforeSave() trigger (or beforeInsert() or beforeUpdate()).

In the delegate class for your table:

Code: Select all
function beforeSave(&$record){     $record->setValue('myfield', strtolower($record->val('myfield'))); }

chichi — Thu Jul 22, 2010 2:59 am

Knowing this, I see how much I can do with this awsome framework. Its so powerful and has more possibilities than I thought. Thanks for your help.