Reputation: 565
I'm confuse. echo is use when you want to show that to front. but I guess importing css file url is not need for show to front because you just refer to location of url.
Sometimes, import css without echo, it's work fine.
<link rel="stylesheet" type="text/css" href="<?php base_url();?>css/animate.css">
but sometimes If I did not use echo, it will not work.
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">
What's this meaning?
Upvotes: 0
Views: 305
Reputation: 21
base_url calls a function, echo in front means display the output of the function.
I believe that the reason why it works "sometimes" is because the file that works is on the same level as the css folder itself. Meaning your index.php will work, however going to {somefolder}/somefile.php wont work, as that too will look for its own css folder, inside {somefolder}.
Generally what I do is place a slash infront of the path itself, that eliminate the need to use a function to begin with, and it also means that no matter how many sub-folders you may have it will always load the same style.css file.
<link rel="stylesheet" type="text/css" href="/css/style.css">
Using that will guarantee it works on all pages you may have, taken you have a css folder in the public_html folder, or website root directory.
Upvotes: 2