简体   繁体   English

Codeigniter,PHP echo base_url()与base_url()有什么不同?

[英]Codeigniter,PHP what is different echo base_url() vs base_url()?

I'm confuse. 我感到困惑。 echo is use when you want to show that to front. 当您想在前面显示回声时,可以使用echo。 but I guess importing css file url is not need for show to front because you just refer to location of url. 但是我猜想导入css文件的URL不需要在最前面显示,因为您只引用URL的位置。


Sometimes, import css without echo, it's work fine. 有时,导入没有回声的CSS可以正常工作。

<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. 但是有时如果我不使用echo,它将无法正常工作。

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">

What's this meaning? 这是什么意思

base_url calls a function, echo in front means display the output of the function. base_url调用函数,前面的echo表示显示函数的输出。

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. 我相信它“有时”起作用的原因是因为起作用的文件与css文件夹本身处于同一级别。 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}. 这意味着您的index.php可以工作,但是转到{somefolder} /somefile.php却行不通,因为这也会在{somefolder}内查找自己的css文件夹。

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. 通常,我要做的是在路径本身的前面放置一个斜杠,从而消除了使用函数开头的需要,这也意味着无论您拥有多少个子文件夹,它都将始终加载相同的样式.css文件。

<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. 使用该方法将确保它可以在您可能拥有的所有页面上运行,在public_html文件夹中或网站根目录中都有一个css文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM