Welcome Guest, Not a member yet? Register   Sign In
Issue with site_url() after upgrade to 4.5.5
#1

(This post was last modified: 11-23-2024, 03:07 PM by SoccerGuy3.)

Upgraded my site from 4.3.8 to 4.5.5 this morning. I have gone through all the changes version by version and have the site basically running again. One issue that has me completely stopped is the behavior of site_url(). I know there were breaking changes around 4.4, but I can't for the life of me see how they apply in this case. What I have...
In my .env file:
PHP Code:
app.baseURL 'https://domain.com/'

app.indexPage '' 


In my view file:
PHP Code:
<class="nav-link" href="<?= site_url() ?>" target="_blank"


In 4.3.8 (and before) this returned:
PHP Code:
<class="nav-link" href="https://domain.com" target="_blank"


In 4.5.5 it is returning:
PHP Code:
<class="nav-link" href="" target="_blank"

If I put a value in:
PHP Code:
app.indexPage 'index' 

I get (in 4.5.5):
PHP Code:
<class="nav-link" href="https://index/index" target="_blank"
If I use the example from the docs (with the original .env file settings):
PHP Code:
<class="nav-link" href="<?= site_url('news/local/123'); ?>" target="_blank"

I get:
PHP Code:
<class="nav-link" href="https://news/news/local/123" target="_blank"


Is there a setting somewhere I missed during the upgrades? Am I missing something obvious in the docs?
Help!
Reply
#2

there are tests in the framework. they pass site_url() checks. have you updated all the files in app? Maybe you replaced the service for URI?
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(This post was last modified: 11-25-2024, 11:24 AM by SoccerGuy3.)

(11-23-2024, 08:50 PM)ozornick Wrote: there are tests in the framework. they pass site_url() checks. have you updated all the files in app? Maybe you replaced the service for URI?

Sorry, I am not understanding your answer or what I need to check exactly. Could you please expand on that with more detail?
Reply
#4

Hmmm... just realized that only on the "home page" is "site_url" returning nothing. On sub pages, site_url is properly returning "domain.com"...

Not sure if it is related, but also noticed that the CI Toolbar is not loading on the home page, but is on the sub pages.
Reply
#5

(This post was last modified: 11-25-2024, 03:19 PM by SoccerGuy3.)

Digging some more, the problem seems to be tied to this error in the logs:

PHP Code:
WARNING 2024-11-25 11:27:04 --> [DEPRECATEDAutomatic conversion of false to array is deprecated in SYSTEMPATH/HTTP/SiteURI.php on line 120.
 1 SYSTEMPATH
/HTTP/SiteURI.php(427): CodeIgniter\HTTP\SiteURI->__construct(Object(Config\App), ''''null)
2 SYSTEMPATH/Helpers/url_helper.php(39): CodeIgniter\HTTP\SiteURI->siteUrl(''nullObject(Config\App))
3 SYSTEMPATH/Debug/Toolbar.php(431): site_url()
4 SYSTEMPATH/Filters/DebugToolbar.php(43): CodeIgniter\Debug\Toolbar->prepare(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response))
5 SYSTEMPATH/Filters/Filters.php(241): CodeIgniter\Filters\DebugToolbar->after(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), null)
6 SYSTEMPATH/Filters/Filters.php(188): CodeIgniter\Filters\Filters->runAfter([...])
7 SYSTEMPATH/CodeIgniter.php(527): CodeIgniter\Filters\Filters->run('auction''after')
8 SYSTEMPATH/CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest(nullObject(Config\Cache), false)
9 SYSTEMPATH/Boot.php(325): CodeIgniter\CodeIgniter->run()
10 SYSTEMPATH/Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
11 FCPATH/index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths)) 


Unless I comment out the HTTPException, this is what error comes up when I try to use site_url() on my home page (https://domain.com/auction)


PHP Code:
CRITICAL 2024-11-25 11:28:21 --> CodeIgniter\HTTP\Exceptions\HTTPExceptionUnable to parse URI"https://"
[MethodGETRouteauction]
in SYSTEMPATH/HTTP/SiteURI.php on line 118.
1 SYSTEMPATH
/HTTP/SiteURI.php(118): CodeIgniter\HTTP\Exceptions\HTTPException::forUnableToParseURI('https://')
2 SYSTEMPATH/HTTP/SiteURI.php(427): CodeIgniter\HTTP\SiteURI->__construct(Object(Config\App), ''''null)
3 SYSTEMPATH/Helpers/url_helper.php(39): CodeIgniter\HTTP\SiteURI->siteUrl(''nullObject(Config\App))
4 SYSTEMPATH/Debug/Toolbar.php(431): site_url()
5 SYSTEMPATH/Filters/DebugToolbar.php(43): CodeIgniter\Debug\Toolbar->prepare(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response))
6 SYSTEMPATH/Filters/Filters.php(241): CodeIgniter\Filters\DebugToolbar->after(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), null)
7 SYSTEMPATH/Filters/Filters.php(188): CodeIgniter\Filters\Filters->runAfter([...])
8 SYSTEMPATH/CodeIgniter.php(527): CodeIgniter\Filters\Filters->run('auction''after')
9 SYSTEMPATH/CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest(nullObject(Config\Cache), false)
10 SYSTEMPATH/Boot.php(325): CodeIgniter\CodeIgniter->run()
11 SYSTEMPATH/Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
12 FCPATH/index.php(56): CodeIgniter\Boot::bootWeb(Object(Config\Paths)) 

Here's the relevant code from SiteURI.php

PHP Code:
        // Fix the current URI
        $uri $this->baseURL $indexPageRoutePath;

        // applyParts
        $parts parse_url($uri);
        if ($parts === false) {
            throw HTTPException::forUnableToParseURI($uri);
        }
        $parts['query']    $query;
        $parts['fragment'] = $fragment;
        $this->applyParts($parts); 


In an effort to get past this and get the app back up and running, I created a simple replacement helper that doesn't have all the bells and whistles of the original, at least gets me running again for now:   NEVERMIND, THIS DIDN'T WORK AS THE TOOLBAR WAS STILL BROKEN.

PHP Code:
if (! function_exists('p42_site_url')) {
 function 
p42_site_url($path NULL){
//Replacement for the built in site_url that stopped working after update to 4.5.5.
if($path) {
$string strtolower($path);
if(
str_starts_with($string,'/')){
$string trim($string,'/');
}
} else {
$string '';
}
$host $_ENV['app.baseURL'];
return 
$host.$string;
}

Reply
#6

Open issue on github?
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#7

In the end I setup a new site with a clean CI install. Ran a diff on all Config, etc files and made any tweaks (nothing related found). Then I started moving my Controllers, Views, etc over in groups until I "broke" the new site. Turned out that the issue was being caused by the auth module CI4-Auth ( https://github.com/glewe/ci4-auth ). Once I moved all my files and disabled all the stuff related to CI-Auth, the problem went away. 
There is a newish release of CI4-Auth that requires CI 4.5. Installed that and took the time to apply my customizations. BAM! All good now. App is finally back to working as it was before the upgrade of CI.
Thanks for your suggestions.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB