by prettyscripts on 2009-08-07 10:50:10
these columns are required for most tables to sign the data. however the save codes are repeated through out the model classes. code repetition is bad programming practice. this is where sfDoctrineActAsSignablePlugin comes to rescue!
once plugin is installed, just add this to schema.yml to automatically add created_by and updated_by columns:
Code:
Table: | |
actAs: | |
Signable: ~ | |
columns: | |
.... |
if you need only one column, say created_by, updated_by can be disabled:
Code:
Table: | |
actAs: | |
Signable: | |
created: { name: created_by, type: integer } | |
updated: { disabled: true } | |
columns: | |
.... |
note line 4: name and type must be specified. ‘~’ doesn’t seem to work.
the default type for these columns is string. you can specify in the schema to use integer. i personally prefer to use user_id (from sfGuardUser), hence the code was hacked to use integer as default.
edit /project/plugins/sfDoctrineActAsSignablePlugin/lib/template/Signable.php, locate the code:
PHP:
protected $_options = array( | |
'created' => array( | |
'name' => 'created_by', | |
'type' => 'string', // change this | |
'disabled' => false, | |
'expression' => false, | |
'options' => array() | |
), | |
'updated' => array( | |
'name' => 'updated_by', | |
'type' => 'string', // change this | |
'disabled' => false, | |
'expression' => false, | |
'onInsert' => true, | |
'options' => array() | |
) | |
); |
lines 4 and 11 above (which is line 25 and 32 in source code), replace type 'string' to 'integer'.