How to use beforeSave in CakePHP 3?

2

I'm trying to get the image array to handle

In CakePHP 2, I did this:

    public function beforeSave($options = array())
    {
    if(!empty($this->data['User']['picture']['name'])...

Could someone explain the new syntax of Cake 3:

beforeSave
Cake\ORM\Table::beforeSave(Event $event, Entity $entity, ArrayObject $options)

?

Thank you

    
asked by anonymous 08.05.2015 / 02:21

1 answer

1

This should help your implementation problem

// Uses da class - além dos demais necessários
use Cake\Event\Event;
use Cake\ORM\Entity;

// Seu método
public function beforeSave(Event $event, Entity $entity, \ArrayObject $options)
{
    if (isset($entity->picture) && !empty($entity->picture)) {
        $entity->set('picture', trim($entity->picture));
    }
}
    
17.09.2015 / 20:46