Add title for item as suffix in url, only for one controller |
Hi
I've an application in CI 3.x I have a special controller which I'd like to make more SEF The actual uri is http://www.myapp.com/index.php/item/detail/325 and I'd like to make it http://www.myapp.com/index.php/item/deta...r-whatever And also I'll remove index.php with .htaccess etc. The question would be: Is there any way to override site_url() and add the item's title (stored in db) as url suffix ? I may create a model's function which can get title and then modify the 19 view files where I call item/detail controller/method but it will be a pain in the a** Maybe another idea? Thanks
Enrique
https://beza.com.ar
Hi,
PHP Code: echo site_url('controller/method/'.$slug); You should also read the manual. URL Helper URI Route A good decision is based on knowledge and not on numbers. - Plato
(03-14-2018, 12:27 AM)salain Wrote: Hi, Sorry, but You should also read the whole question I stated that I'd like to avoid modifying/echoing site_url() again in the 19 view files and try to find some workaround (to solve this) in the controller itself, or routes file, or any other place Thanks anyway
Enrique
https://beza.com.ar
Show more code you may get a better answer
A good decision is based on knowledge and not on numbers. - Plato
You will need to adapt it in your model and set your route for item/detail/(:num)/(:any)...
PHP Code: protected function setUri($data) This enables you to call URL's like the StackOverflow (base_url/questions/(:num)/(:uri_title)). This is a beforeInsert/beforeUpdate trigger for CodeIgniter 4, one row at a time. Then you can get the item by primary key and have a SEF uri. |
Welcome Guest, Not a member yet? Register Sign In |