# Adding Simple Slug Generation doest work

**URL:** <https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880>\
**Category:** Need Help\
**Created:** [September 6, 2018, 9:09pm UTC](https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880 "2018-09-06T21:09:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acquesta](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/acquesta/32/1149_2.png) [@Acquesta](https://discourse.cakephp.org/u/Acquesta)\
**Post date:** [September 6, 2018, 9:09pm UTC](https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880/1 "2018-09-06T21:09:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [September 7, 2018, 4:01pm UTC](https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880/2 "2018-09-07T16:01:31Z")

</div>

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](https://book.cakephp.org/3.0/en/orm/behaviors.html#defining-event-listeners)

---

<div class="post-metadata">

**Author:** ![squeakychair](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@squeakychair](https://discourse.cakephp.org/u/squeakychair)\
**Post date:** [August 21, 2019, 6:49pm UTC](https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880/3 "2019-08-21T18:49:21Z")

</div>

Did you find a solution to the issue? I’m having the same issue with the example code provided in the tutorial.

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [August 22, 2019, 6:42pm UTC](https://discourse.cakephp.org/t/adding-simple-slug-generation-doest-work/4880/4 "2019-08-22T18:42:08Z")

</div>

What is the error you’re getting?  
I accidentally broke my crystal ball yesterday and am still waiting for a new one from AliExpress…
