public function beforeSave(Event $event, $entity, $options = [])
    {
        if ($this->_table->hasField($this->config('createdByField')) ||
            $this->_table->hasField($this->config('modifiedByField'))
        ) {
            $userId = $this->_getUserId();
            if ($userId > 0) {
                $entity->set($this->config('modifiedByField'), $userId);
                if ($entity->isNew()) {
                    $entity->set($this->config('createdByField'), $userId);
                }
            }
        }

        return true;
    }
public function beforeSave(Event $event, $entity, $options = [])
    {
        if ($this->_table->hasField($this->config('createdByField')) ||
            $this->_table->hasField($this->config('modifiedByField'))
        ) {
            $userId = $this->_getUserId();
            if ($userId > 0) {
                $entity->set($this->config('modifiedByField'), $userId);
                if ($entity->isNew()) {
                    $entity->set($this->config('createdByField'), $userId);
                }
            }
        }

        return true;
    }
public function beforeSave ( Event $ event , $ entity , $ options = [ ] ) { if ( $ this -> _table -> hasField ( $ this -> config ( 'createdByField' ) ) || $ this -> _table -> hasField ( $ this -> config ( 'modifiedByField' ) ) ) { $ userId = $ this -> _getUserId ( ) ; if ( $ userId > 0 ) { $ entity -> set ( $ this -> config ( 'modifiedByField' ) , $ userId ) ; if ( $ entity -> isNew ( ) ) { $ entity -> set ( $ this -> config ( 'createdByField' ) , $ userId ) ; } } } return true ; }
Run before a model is saved.

@param \Cake\Event\Event $event The event that was triggered
@param \Cake\ORM\Entity $entity The entity being saved
@param array $options Array of options for the save operation
@return bool True if save should proceed, false otherwise
Run before a model is saved .