namespace Orm;
class Observer_CreatedBy extends Observer
{
/**
* @var string property to set the creation by on
*/
public static $property = 'created_by';
/**
* @var string current_user from Warden
*/
public static $current_user = \Warden::current_user()->id;
protected $_current_user;
protected $_property;
public function __construct($class)
{
$props = $class::observers(get_class($this));
$this->_current_user = isset($props['current_user']) ? $props['current_user'] : static::$current_user;
$this->_property = isset($props['property']) ? $props['property'] : static::$property;
}
public function before_insert(Model $obj)
{
$obj->{$this->_property} = $this->_current_user;
}
}
public static $current_user = \Warden::current_user()->id;
It looks like you're new here. If you want to get involved, click one of these buttons!