CodeIgniter Forums
Different values from current_url and service('uri') - 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: Different values from current_url and service('uri') (/showthread.php?tid=86872)



Different values from current_url and service('uri') - b126 - 02-22-2023

I came across some strange behavior between two similar functions. Why isn't base_url returned with the second call (current_url)?

service('uri')

Code:
$uri = service('uri');
dump($uri);

^ CodeIgniter\HTTP\URI {#12 ▼
  #uriString: null
  -baseURL: "http://myhost/"
  #segments: array:4 [▶]
  #scheme: "http"
  #user: null
  #password: null
  #host: "myhost"
  #port: null
  #path: "committees/BE/dossiers/new"
  #fragment: ""
  #query: & []
  #defaultPorts: array:4 [▶]
  #showPassword: false
  #silent: false
  #rawQueryString: false
}


current_url(true)

Code:
$uri2 = current_url(true);
dump($uri2);

^ CodeIgniter\HTTP\URI {#9905 ▼
  #uriString: null
  -baseURL: null
  #segments: array:4 [▶]
  #scheme: "http"
  #user: null
  #password: null
  #host: "myhost"
  #port: null
  #path: "/country/BE/dossiers/new"
  #fragment: ""
  #query: []
  #defaultPorts: array:4 [▶]
  #showPassword: false
  #silent: false
  #rawQueryString: false
}



RE: Different values from current_url and service('uri') - kenjis - 02-22-2023

Thank you. I created an issue: https://github.com/codeigniter4/CodeIgniter4/issues/7296

The current code around URI is complicated.
Both are the same current URI, so the values should be the same.
But some values are not the same.


RE: Different values from current_url and service('uri') - kenjis - 02-22-2023

By the way, what do you want for the current URI?

When you navigate to http://localhost:8080/,
is the current URI http://localhost:8080/ or http://localhost:8080/index.php
when indexPage is 'index.php'?