Skip to content

Instantly share code, notes, and snippets.

@mattlanham
Created February 2, 2012 19:18
Show Gist options
  • Save mattlanham/1725205 to your computer and use it in GitHub Desktop.
Save mattlanham/1725205 to your computer and use it in GitHub Desktop.
<?php
namespace Orm;
class Observer_Accountid extends Observer
{
/**
* @var string property to set the timestamp on
*/
public static $property = 'account_id';
protected $_property;
public function __construct($class)
{
$props = $class::observers(get_class($this));
$this->_property = isset($props['property']) ? $props['property'] : static::$property;
}
public function before_insert(Model $model)
{
if(!$model->account_id) $model->{$this->_property} = \Session::get('account_id', \Inquirely::get_account()->id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment