简体   繁体   English

外部CSS链接在codeIgniter中不起作用

[英]External CSS link is not working in codeIgniter

I have tried base_url() function, But I didn't understand where am I wrong? 我已经尝试过base_url()函数,但是我不明白我在哪里错了? I have also mentioned - $this->load->helper ('URL'); 我也提到过- $this->load->helper ('URL'); in function abc() in controller. 在控制器中的函数abc()中。 Here is my code, 这是我的代码,

<link href="<?PHP echo base_url();?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/CSS"/>

It is because of the way you are referencing the css file. 这是因为您引用css文件的方式。 You can use this: 您可以使用此:

<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">

Or you can use this: 或者您可以使用以下命令:

<link href="/assets/css/bootstrap.min.css" rel="stylesheet">

Notice the / at the start of the link, this means the browser will look from the base of your website url (your domain). 注意链接开头的/,这表示浏览器将从您的网站网址(您的域)的底部查找。 If you miss it out it will use the relative part of the url, so if you are referencing a controller it will assume this is a sub folder for the location of the css file too. 如果您错过了它,它将使用URL的相对部分,因此,如果您引用的是控制器,它将假定它也是css文件位置的子文件夹。

You are better off with the base_url format given first, if you are using a local host for development then you will not have any problems with the url base. 首先使用base_url格式会更好,如果使用本地主机进行开发,则url base不会有任何问题。 If you app is moved to a sub folder on another site or with a sub domain etc you will not have any problems either. 如果您将应用程序移动到另一个站点上的子文件夹或具有子域等,则也不会有任何问题。

So base_url is the way to go here. 所以base_url是这里的方法。 More info in the docs. 文档中的更多信息。

http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url

I am thinking you have not set tour base_url if your base url shows Ip address in links your css will not work 我认为如果您的基本URL在链接中显示IP地址,而您的CSS无法使用,则您尚未设置游览base_url

You need to set this value 您需要设置此值

$config['base_url'] = 'http://localhost/yourproject/';

Head

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

Make sure your assets folder out side of application 确保您的资产文件夹位于应用程序之外

application

assets

A good thing is to also autoload url helper lower case. 一件好事是还自动加载url helper小写。

$autoload['helper'] = array('url');

Use below code to link your css : 使用以下代码链接您的css:

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

make sure you have configure the CI configuration properly : CONFIG.PHP 确保已正确配置CI配置:CONFIG.PHP

$config['base_url'] = 'http://localhost/your_project/';
$config['index_page'] = '';

AUTOLOAD.PHP 自动加载

$autoload['helper'] = array('url');

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

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