Adding Simple Slug Generation doest work


#1

In the tutorial this code doesnt work, can someone try help me, please?

public function beforeSave($event, $entity, $options)
{
if ($entity->isNew() && !$entity->slug) {
$sluggedTitle = Text::slug($entity->title);
// trim slug to maximum length defined in schema
$entity->slug = substr($sluggedTitle, 0, 191);
}
}


#2

Do you get any error message? Does your code get into beforeSave? If yes, than try to debug what happens there.

Are you on CakePHP 3? Because your code is different from the cookbook.
https://book.cakephp.org/3.0/en/orm/behaviors.html#defining-event-listeners