= sfGuardPropelAuthoredBehaviorPlugin = A common task for read/write websites is to save the user that is creating or modifying a record. sfGuardPropelAuthoredBehaviorPlugin is an addon to sfGuard that automatically logs the authenticated user's profile. The profile id is written to the table with the behavior enabled when calling save() on a model instance. == Installation == * Install [wiki:sfGuardPlugin] using the instructions: http://trac.symfony-project.com/trac/wiki/sfGuardPlugin You must complete the steps to add user profiles to your application. This plugin uses the profile model because it is in your application schema's package, making friendly relations possible. * Install this plugin: {{{ symfony plugin-install http://plugins.symfony-project.com/sfGuardPropelAuthoredBehaviorPlugin }}} * Enable Propel behavior support in `propel.ini`: {{{ propel.builder.AddBehaviors = true }}} * Activate the behavior for one of your Propel models: {{{ // lib/model/Article.php class Article { } sfPropelBehavior::add('Article', array('sfGuardPropelAuthoredBehavior')); }}} * Add a column to the model that will hold the profile id of the user that created or edited the record. By default, it should follow the convention of "foreign_table_name_id", where the foreign table is your sfGuard user profile table. This can be sfGaurd's default, or the one that you defined in your settings.yml config file. For example, consider the following schema using the default profile table: {{{ propel: sf_guard_user_profile: _attributes: { phpName: sfGuardUserProfile } id: user_id: { type: integer, index: unique } name: varchar(100) article: id: sf_guard_user_profile_id: title: varchar(100) body: longvarchar }}} You may define another column to use on a per-table basis: {{{ sfPropelBehavior::add('Article', array('sfGuardPropelAuthoredBehavior' => array('column' => 'author_id'))); }}} * Rebuild your model and update your database schema, then load fixtures if desired. {{{ symfony propel-build-all symfony propel-load-data <app> }}} == Usage == With every call to save(), the column you added will be set to the profile id of the currently authenticated user. You can disable the behavior for all subsequent calls to save() with: {{{ sfPropelAuthoredBehavior::disable(); }}} And then enable the behavior again: {{{ sfPropelAuthoredBehavior::enable(); }}} == Changelog == === 0.1.1 === * Fixed an instance of the old behavior name (authored). This was causing you to not be able to specify an alternate column where the profile id is stored. (Felix Eckhofer)