# URL Change in address bar

**URL:** <https://discourse.cakephp.org/t/url-change-in-address-bar/1059>\
**Category:** Need Help\
**Created:** [August 27, 2016, 1:27pm UTC](https://discourse.cakephp.org/t/url-change-in-address-bar/1059 "2016-08-27T13:27:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhoopathi\_smash](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bhoopathi\_smash](https://discourse.cakephp.org/u/bhoopathi_smash)\
**Post date:** [August 27, 2016, 1:27pm UTC](https://discourse.cakephp.org/t/url-change-in-address-bar/1059/1 "2016-08-27T13:27:27Z")

</div>

I’m using cakephp 3.x version:

And I have

Controller = Booking and Function = packdetails and parameter= 4

parameter is primary id of my packdetails, and it’s dynamic

## BOOKING CONTROLLER

function packdetails($id){

}

MY CURRENT URL: [http://hostname/booking/packdetails/4](http://hostname/booking/packdetails/4)

I need URL as some thing like:

[http://hostname/booking/packdetails/](http://hostname/booking/packdetails/) (or) [http://hostname/booking/packdetails/test](http://hostname/booking/packdetails/test) (or) [http://hostname/booking/test](http://hostname/booking/test)

Can i change it by Router(config/routes.php)  
If its possible , please help me on this

thank you dudes…

---

<div class="post-metadata">

**Author:** ![ali](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ali/32/123_2.png) [@ali](https://discourse.cakephp.org/u/ali)\
**Post date:** [August 28, 2016, 4:34pm UTC](https://discourse.cakephp.org/t/url-change-in-address-bar/1059/2 "2016-08-28T16:34:03Z")

</div>

Yes, you can simply connect the url as you would in a html helper link:

```
$routes->connect('/booking/packdetails', ['controller' => 'Booking', 'action' => 'packdetails', 4]);

```

This would create a route only for the id 4.

But if you intend to add it as a dynamic slug for all id’s, you’ll need to have it in your table and use it instead of the id.

---

<div class="post-metadata">

**Author:** ![bhoopathi\_smash](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bhoopathi\_smash](https://discourse.cakephp.org/u/bhoopathi_smash)\
**Post date:** [August 29, 2016, 8:08am UTC](https://discourse.cakephp.org/t/url-change-in-address-bar/1059/3 "2016-08-29T08:08:44Z")

</div>

Thanks dude for your opinion. I’m using dynamic id, i don’t know how to use slug can you please show me how to use slug for my above action…

thanks 🙂

---

<div class="post-metadata">

**Author:** ![ali](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ali/32/123_2.png) [@ali](https://discourse.cakephp.org/u/ali)\
**Post date:** [August 29, 2016, 8:39am UTC](https://discourse.cakephp.org/t/url-change-in-address-bar/1059/4 "2016-08-29T08:39:17Z")

</div>

No problem; Using slugs is fairly straightforward, but you do have to add them to your DB table, in addition to ID’s.

So when new entries are added, you should fill the slug field with a sluggified version of for instance the title, so something like “My new blog entry” should be saved as the slug “my-new-blog-entry”. More on that here: [http://book.cakephp.org/3.0/en/core-libraries/text.html#creating-url-safe-strings](http://book.cakephp.org/3.0/en/core-libraries/text.html#creating-url-safe-strings)

Then in your view action, instead of using the ID of the entry to find it, you’ll have to use the slug. This means that you need to modify all related find functions. You also won’t be able to use -\>get(), as it uses the ID by default.

Lastly, you’ll need to change your actual links to the view page so that they use the slug instead of the ID. And that’s it!
