beta 2 - base_url() inconsistent in namespaces - 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: beta 2 - base_url() inconsistent in namespaces (/showthread.php?tid=73335) |
beta 2 - base_url() inconsistent in namespaces - devops - 04-12-2019 Greetings. Is this a bug or am I missing something basic? base_url() is correct when referenced in the app namespace, but is incorrect in other namespaces (i.e. modules). site_url() is correct in both namespaces. Here is a minimal example of the code I used to create, use, and route modules and the "quirk". PHP Code: SETUP: Any ideas why the redirect to base_url() fails here? Same result as $this->response->redirect('/'). Also, it seems that the response class is not available from any models code. Is that by design, can I redirect in the model code, or did I goof up there too? Cheers. RE: beta 2 - base_url() inconsistent in namespaces - kilishan - 04-12-2019 base_url() should be the same from any namespace. So that definitely sounds like a bug. PLease file a bug report for that! The request and response classes are only automatically inserted as a property in controllers, so $this->response is only available in controller, not model. In my opinion you shouldn't be messing with response or requests from within a model, but if you want to, you can always grab the current instance through the services: Code: $request = \Config\Services::request(); There's two ways to grab a service so I showed both for example, but either way would work with any service. RE: beta 2 - base_url() inconsistent in namespaces - devops - 04-12-2019 Thanks! I agree that navigation is controller only. I was just attempting shortcuts in development/test. |