Welcome Guest, Not a member yet? Register   Sign In
Why does site_url not terminate with a slash?
#1

[eluser]WolfgangA[/eluser]
Hello,

i wonder why site_url() does not terminate the url with a slash where base_url() does?
(and also basepath and apppath)

From the src in url_helper i see that site_url() just appends the config item for index.php. But why not adding also a slash to be consistent?
Example ( i use a separate app dir):
Code:
BaseURL: https://192.168.250.112/vflan/app/
SiteURL: https://192.168.250.112/vflan/app/index.php
AppPath: /var/www/html/vflan/app/
BasePath: /var/www/html/vflan/ci/system/

to be
Code:
SiteURL: https://192.168.250.112/vflan/app/index.php/

Regards

Wolfgang
#2

[eluser]tonanbarbarian[/eluser]
I could be wrong but I think it is because you can use the url suffix in the config to make all urls end in .html for example
Site url is designed to have parameter passed to it that creates the url
Code:
site_url('controller/method')
would return
Code:
https://192.168.250.112/vflan/app/index.php/controller/method
and if the config url suffix is set
Code:
$config['url_suffix'] = ".html";
would return
Code:
https://192.168.250.112/vflan/app/index.php/controller/method.html
so if site_url put the / on the end the url suffix would not work
Code:
https://192.168.250.112/vflan/app/index.php/controller/method/.html
Now you might be wondering what url site_url is going to create for the case when the parameter is empty
well it determine what your default controller is from your config and goes to the index method
Code:
$route['default_controller'] = "welcome";
site_url() will produce
Code:
https://192.168.250.112/vflan/app/index.php/welcome/index.html
#3

[eluser]Phil Sturgeon[/eluser]
Agreed.

Also, if you end it with a / then it is a folder, without and its a file. In theory this mimics normal behaviour a lot better as you arent loading folders, but web-pages.
#4

[eluser]WolfgangA[/eluser]
Thank you. I was just wondering because when i try to call a controller/method via XHR from JS, then i have to add a slash myself like:
Code:
/controller/method

where inside Ci (using for example redirect) i cand do:
Code:
controller/method

and i thought this would be a bit inconsistent.

Regards

Wolfgang
#5

[eluser]xwero[/eluser]
You can hack it easy. change line 280 of the config.php library from
Code:
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
to
Code:
$suffix = ($this->item('url_suffix') == FALSE) ? '/' : $this->item('url_suffix');
#6

[eluser]WolfgangA[/eluser]
Thank you for your help.
I found this in the config, but try to make as few changes as possible to avoid "side-effects".
Basically i wondered why this is implemented as it is.




Theme © iAndrew 2016 - Forum software by © MyBB