Can someone check base_url() and base_url("param") |
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 ![]()
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?
@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);
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);
@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.
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.
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))
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"> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |