Hi. I made user email verification as model's behavoir, but i have some troubles. The behavior's code:
namespace App\Models\Behaviors;
use Phalcon\Mvc\Model\Behavior,
Phalcon\Mvc\Model\BehaviorInterface;
use App\Models\Verify;
class VerifyEmail extends Behavior implements BehaviorInterface {
protected $event;
function __construct($field = 'verify_email',$event_name = 'unkown')
{
$this->field = $field;
$this->event = $event_name;
}
public function notify($eventType, $model)
{
switch ($eventType)
{
case 'afterCreate':
$di = $model -> getDI();
$security = $di -> getSecurity();
$verify = new Verify;
$verify -> event = $this->event;
$verify -> data = $model -> email;
$verify -> user_id = $model -> id;
$verify -> code = $security -> generateVerifyCode();
$verify -> create();
$field = $this->field;
$model -> $field = $verify -> id;
$model -> update();
// Sending email
break;
default:
}
}
}
As you see, i redefined __construct
method to set params (field,event_name)
But i need to set params dinamically, like:
$this -> addBehavior(new VerifyEmail(array(
'afterCreate' => array(
'field' => 'verify_email',
'event_name' => 'register'
)
)));
I have no ideas how to do it, i think phalcon cared about that,and there are some methods to make it. I didn't found any reciepes in documentation. I'm not sure, i use behavior rightly. I would be very pleasure for any help.
P.S: sorry for bad English :)