I wrote custom type of behavior to my project needs. It's looks like this:
<?php
namespace Ely\Behavior;
use Phalcon\Mvc\Model\Behavior;
use Phalcon\Mvc\Model\BehaviorInterface;
class IPStampable extends Behavior implements BehaviorInterface {
public function notify($type, $model) {
$options = $this->getOptions();
if (array_key_exists($type, $options)) {
$options = $options[$type];
$model->$options['field'] = \Phalcon\DI::getDefault()->getRequest()->getClientAddress();
}
}
}
But when i try to do this (in model initialize() method):
$this->addBehavior(new Timestampable(array(
"beforeValidationOnCreate" => array(
"field" => "registered"
)
)));
$this->addBehavior(new IPStampable(array(
"beforeValidationOnCreate" => array(
"field" => "reg_ip"
)
)));
I still get "reg_ip is required", but I checked - the value is set