Hi, I'm trying to use an observer to intercept fields before save and after retrieval, so that I can encrypt some values.
I want to be able to exclude certain fields defined from within the model itself, but I'm unsure how to approach this. I've tried the following:
Within my model:
protected static $_observers = array( 'Encryption' => array( // set field true to exclude from validation 'exclude' => array( 'size' => true ) ), )
class Observer_Encryption extends Orm\Observer { public static $exclude = array();
public function __construct($class) { $props = $class::observers(get_class($this)); $this->_props = $props; $this->_exclude = isset($props['exclude']) ? $props['exclude'] : static::$exclude; }
// called by the save() method before anything is done public function after_load(Orm\Model $model) { \Log::info('[props val: '.print_r( $this->_props, true ));
Thanks for this, I have the code together but I still can't seem to get the props to come through, perhaps its due to name spacing or similar? I have the observer in classes/observer/encryption defined as "Observer_Encryption"
I can't work out why the param isn't being passed to the observer :(
If the file is /classes/observer/encryption.php, and the class is called "Observer_Encryption", then it doesn't have a namespace (it is in the global namespace).
Thanks, that is how it's currently set. But that isn't allowing params to be passed, so I need to set a namespace presumably so I can have a fully qualified namespace?