Hi all

Today I will share tip implement logic event model. I assuming have two model implement method beforeDelete and beforeUpdate

    class Job extends ModelBase
    {
    [...]
    **
     * Implements hook beforeDelete
     *
     * Check permission before deleted task
     *
     * @return  bool
     */
    public function beforeDelete()
    {
       // d($this->idUser);
        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be deleted'));

            return false;
        }

        return true;
    }
    /**
     * Implements hook beforeUpdate
     *
     * Check permission before updated task
     *
     * @return  bool
     */
    public function beforeUpdate()
    {
        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be edit'));
            return false;
        }
        return true;
    }

Then model Task

    class Task extends ModelBase
    {
    [...]
    **
     * Implements hook beforeDelete
     *
     * Check permission before deleted task
     *
     * @return  bool
     */
    public function beforeDelete()
    {
       // d($this->idUser);
        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be deleted'));

            return false;
        }

        return true;
    }
    /**
     * Implements hook beforeUpdate
     *
     * Check permission before updated task
     *
     * @return  bool
     */
    public function beforeUpdate()
    {
        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be edit'));
            return false;
        }
        return true;
    }

In this case two model, but many model used code above . How to reusable code ? I have solution on forum Phalcon, I think usefull for you here solution

You can use PHP feature Trait : http://php.net/manual/en/language.oop5.traits.php

<?php


namespace Zphalcon\Models;


trait CommonBehaviour
{
    /**
     * Implements hook beforeDelete
     *
     * Check permission before deleted task
     *
     * @return  bool
     */
    public function beforeDelete()
    {
       // d($this->idUser);
        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be deleted'));

            return false;
        }

        return true;
    }
    /**
     * Implements hook beforeUpdate
     *
     * Check permission before updated task
     *
     * @return  bool
     */
    public function beforeUpdate()
    {

        if ($this->idUser != (int)$this->getDI()->getSession()->get('auth')['id']) {
            $this->getDI()->getflashSession()->error(t('The object is not owner, it can\'t be edit'));
            return false;
        }
        return true;
    }
}

Finaly in orther model you must call it