Back

Editing, Updating and Creating Records
defaultLens
On new record, these are the default values of specified fields When creating a new record, you might want a default value to be automatically entered. You can enter a normal string (without quotes) or number, or generate the value dynamicly using PHP or your RDBMS. Default values can be hard-coded values, or you can execute PHP code if you prefix with the equals(=) character. Dates can either be generated in Unix timestamp format provided you return the value as an integer, or in 'Y-m-d H:i:s' format. Executing PHP Code When you want the value to be dynamically generated by PHP, set the first character to an equals (=) to treat the following text as PHP code. To generate the current date, use the PHP time function like this: =time() PHP Globals To access global variables, before 3.2, you needed to use the following: =$GLOBALS['PHP_SELF'] Since 3.2, you can use this directly: =$PHP_SELF Database Example To access the ADODB connection from here, use the following example, which passes the connection object to the getvalue function:
    $lens->defaultLens = 'col1^=getvalue($this->lens->connection)';
Executing SQL Code Sometimes, you have a read-only field whose value is generated by your SQL server and not by the user. You can do this by setting the first character to percentage (%) to treat the following text as SQL code. Since 2.5.2, you can also put PHP global variables in the SQL string. To set a column to a random number in Microsoft SQL server, use the rand function like this: %rand() Syntax `To set a field called thetime to the current datetime: $lens->defaultLens = 'thetime^=time()' To execute a standard SQL function for a field called rr: $lens->defaultLens = 'rr^%rand()';` Basic:No Advanced/Enterprise:Yes DynamicEdit:Yes [Version 1.0]