![]() |
Can someone check base_url() and base_url("param") - 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: Can someone check base_url() and base_url("param") (/showthread.php?tid=77483) |
Can someone check base_url() and base_url("param") - John_Betong - 09-06-2020 I have been trying to correctly use the base_url() function and having trouble ![]() I find that: 1. echo base_url() issues the correct URL 2. echo base_url(). $param issues the correct URL 3. echo base_url($param) issues an INCORRECT URL I have checked the ./system/Helpers/url_helper.php source code and it is not easy when trying to debug using the Sublime text editor ![]() RE: Can someone check base_url() and base_url("param") - SteeveDroz - 09-06-2020 Hi, I'd need 3 more informations to answer that question: 1. Where did you write that code (in which controller/model/view/library/…)? 2. What is the incorrect result you get? 3. What is the expected result? RE: Can someone check base_url() and base_url("param") - John_Betong - 09-06-2020 @SteveDroz, This is the View script PHP Code: <?php declare(strict_types=1); The above script $URL is correct and displays: Quote:$URL = base_url() .'/' .$key; Using this script in accordance with the manual produces: Quote:$URL = base_url($key); RE: Can someone check base_url() and base_url("param") - SteeveDroz - 09-07-2020 Ah, I see! Your problem comes from the fact that base_url($param) uses relative URIs. That means that it will display a page according to your current location. To avoid that, you can prefix your path with a "/" : PHP Code: base_url($somethingWithASlash); or PHP Code: base_url('/'.$somethingWithoutASlash); RE: Can someone check base_url() and base_url("param") - John_Betong - 09-07-2020 @SteveDroz, According to the CI4 manual it is not necessary to precede the parameter with a leading slash. Also I think that would give the URL two slashes. From the manual: Quote:echo base_url('blog/post/123'); I was hoping someone could confirm the script and if the output is the same as mine I will raise a error request. RE: Can someone check base_url() and base_url("param") - SteeveDroz - 09-07-2020 Oh yeah… I looked at the code and saw it was using relative URIs. I must have misread a line, sorry about my false answer. I don't intend to try to correct your way of doing, you seem way more expert than I am with CI4, but I don't understand why you put that code in the View instead of the Controller, so I'm not sure how to help you further. RE: Can someone check base_url() and base_url("param") - Gary - 09-07-2020 I make extensive use of the base_url() function in my code... and it still seems to be working fine under 4.0.4 (and some of its later commits). Though, I typically use it like this: Code: if (isset($_REQUEST)) Code: if ($honeypot->hasContent($request)) RE: Can someone check base_url() and base_url("param") - InsiteFX - 09-07-2020 You do not need the base_url in route_to if you have defined a route for that controller. Example: PHP Code: $routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes) And to go to my dashboard: PHP Code: <li class="nav-item d-none d-sm-inline-block"> |