Adding Simple Slug Generation doest work


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);


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.