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
MY CURRENT URL: http://hostname/booking/packdetails/4
I need URL as some thing like:
http://hostname/booking/packdetails/ (or) http://hostname/booking/packdetails/test (or) http://hostname/booking/test
Can i change it by Router(config/routes.php)
If its possible , please help me on this
thank you dudes…
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.
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…
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
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!