Remove segment from url in multi language site - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Remove segment from url in multi language site (/showthread.php?tid=78644) |
Remove segment from url in multi language site - eleumas - 02-19-2021 Hi! i have this code... View: PHP Code: <a href="<?php echo base_url('it/article/'.$a['slug']);?>">Blog Title</a> Routes: PHP Code: $routes->add('(:any)/it/article', 'It/Main::article/$1'); ..and this link: www.mysite.com/it/article/title I would like remove the word article form the link. My new link should be: www.mysite.com/it/slug Thanks for the support. RE: Remove segment from url in multi language site - kenjis - 02-20-2021 What's your problem? If you want to remove `article`, just remove it. PHP Code: <a href="<?php echo base_url('it/'.$a['slug']);?>">Blog Title</a> RE: Remove segment from url in multi language site - demyr - 02-20-2021 (02-19-2021, 12:00 PM)eleumas Wrote: Hi! i have this code... using only :any() should meet your needs. Or try (:segment) RE: Remove segment from url in multi language site - eleumas - 02-22-2021 (02-20-2021, 04:19 AM)demyr Wrote: using only :any() should meet your needs. Or try (egment) Thanks for reply and help me @demyr! I tried to use only :any or egment: PHP Code: $routes->add('(:any)/it', 'It/Main::article/$1'); but i have this error: Code: Trying to access array offset on value of type null Maybe the issue is in my controller? This is my snippet: PHP Code: public function article() Thanks for the support! RE: Remove segment from url in multi language site - demyr - 02-22-2021 It looks like you are trying to add and view the result within the same method (It/Main::article). Have you tried seperating them? Plus, can you see any response data from your controller, I mean for example: PHP Code: $slug = \Config\Services::request()->uri->getSegment(2); RE: Remove segment from url in multi language site - eleumas - 02-22-2021 (02-22-2021, 06:05 AM)demyr Wrote: It looks like you are trying to add and view the result within the same method (It/Main::article). Have you tried seperating them? Plus, can you see any response data from your controller, I mean for example: Hi @demyr! I have a view called blog with categories and articles for each category. blog method: PHP Code: public function blog() article method: PHP Code: public function article() Routes: PHP Code: // TEST The error is the same: Trying to access array offset on value of type null https://demo.samuelesantoni.com/host/CI4-1-1.png I have this code in another site with one language, CI 4.0.4 and PHP 7.4 and all works fine! I tried your code and the uri segment is correct i can see the answer from my controller. https://demo.samuelesantoni.com/host/CI4-result.png Thanks for help me! RE: Remove segment from url in multi language site - demyr - 02-23-2021 Oh. Have you tried PHP Code: $routes->get('{locale}/(:any)', 'It/Main::article/$1'); By the way, you said that you could retrieve data when you try on Controller but you didn't share it. And it seems like it cannot reach that meta_title. |