[英]how link to my .css file in codeigniter
I have a design problem with CodeIgniter. 我有CodeIgniter的设计问题。 The path to my CSS file is defined like this: 我的CSS文件的路径定义如下:
<link href="<?php echo base_url(); ?>asset/main.css"
rel="stylesheet" type="text/css" media="all">
But it is not working properly. 但是它不能正常工作。
Try this will work, 试试这个会起作用,
<link href="<?php echo base_url('asset/main.css'); ?>" rel="stylesheet" type="text/css" media="all">
you can use url_helper, 您可以使用url_helper,
if ( ! function_exists('base_url'))
{
function base_url($uri = '')
{
$CI =& get_instance();
return $CI->config->base_url($uri);
}
}
Use this <?php echo base_url(); ?>
使用此<?php echo base_url(); ?>
<?php echo base_url(); ?>
<link rel="stylesheet" href="<?php echo base_url(); ?>asset/css/bootstrap.css" />
<link rel="stylesheet" href="<?php echo base_url(); ?>asset/css/main.css" />
in config/config.php
在config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
In config/autoload.php
在config/autoload.php
$autoload['helper'] = array('url');
Your .htaccess
will be 您的.htaccess
将是
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So your folder structurer would be like this 所以您的文件夹结构器将像这样
1. application
2. asset
1. css
- bootstrap.css
- main.css
2. images
3. index.php
4. .htaccess
5. system
You can check this. 您可以检查一下。
In config.php: 在config.php中:
$config['base_url'] = URL;
Go to 去
applicatino/confg/autoload.php. applicatino / confg / autoload.php。
$autoload['helper'] = array('html','url');
<link rel="stylesheet" src="<?php echo base_url('assets/stylesheets/main.css')?>"/>
//OR
<?php echo link_tag('assets/stylesheets/main.css')?>
//Image
<?php echo img('asset/images/learnersway.jpg')?>
//OR
<img src="<?php echo base_url('asset/images/learnersway.jpg')?>" />
//Javascript
<script src='asset/javascript/yourscript.js'></script>
Visit this link: https://ellislab.com/codeigniter%20/user-guide/helpers/html_helper.html 访问此链接: https : //ellislab.com/codeigniter%20/user-guide/helpers/html_helper.html
first create a folder in the root 首先在根目录中创建一个文件夹
Like css// css folder application model view 像css // css文件夹一样的应用程序模型视图
than make the base url 比使基本URL
in config file $config['base_url'] = 'localhost://codegniter/'; 在配置文件$ config ['base_url'] ='localhost:// codegniter /'; url of the site 网站网址
now if you want to include the css file in the site header put the line like this in header or other file 现在,如果要在站点标题中包含css文件,请将这样的行放在标题或其他文件中
" rel="stylesheet" type="text/css"> “ rel =” stylesheet“ type =” text / css“>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.