Back

Editing, Updating and Creating Records
keyVariable
Edit a record based on a global variable One way of forcing phpLens to view/edit a specific record is by setting a global variable in this way: `$lens->sql = "=select * from table where id=\$ID"; $lens->keyCol = 'table_id';` However this is a problem when we want to create a new record, and continue showing this record after it is created. Initially, $ID will be empty, and we need a mechanism to update $ID after the record is created. The keyVariable property solves this problem, because phpLens will auto-update $ID after the record is created. `$lens->sql = "select * from table"; $lens->keyVariable = "ID";` In the above example, $ID must be a global session variable. Now when creating a new record, $ID is updated with the created record's serial id, if the database supports serial id's (mssql, mysql). If the database does not support serial id's, then we provide a second parameter to keyVariable where you can define some sql to execute to obtain the primary key of the newly inserted record. In the following example, we store the serial id in an oracle sequence: `$lens->keyVariable = "ID/select sequence1 from dual";` In the above example, you will still need to define an oracle trigger which sets 'table_id' to sequence1.nextval. Also note the seperator used is the option seperator (/) and not the field seperator (^). Note that if $ID is already defined, then instead of showing the New Record form, we will be viewing or editing the record specified by $ID. Limitations: Only works with numeric/integer primary keys currently. Basic:No Advanced/Enterprise:Yes DynamicEdit:No [Version 3.1]