dpf56454 2017-10-16 18:52
浏览 112

在codeigniter视图中加载CSS的正确方法

My base url in config is : $config['base_url'] = 'http://localhost/ci/';

My CSS folder is on root level(so ci).

In the view I tried:

<head>
    <style> @import url('<?=base_url()?>/css/styles.css'); </style>
</head>

and

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

both fail. what is the correct way to import a CSS file using the Codeigniter framework

Here is how my .htaccess file looks like :

    <IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>
  • 写回答

2条回答

  • dousha4804 2017-10-16 20:04
    关注

    I use this approach:

    folder structure:

    example.com
    |_ application
    |_ assets
    |_ system

    CI 2.x

    I've set $config['base_url'] = '';, this will work for local server and production server

    CI 3.x

    WARNING: You MUST set this ($config['base_url']) value! so I use below code to differentiate between local server and production server :

    if ($_SERVER["HTTP_HOST"]=='ex.ample')
        $config['base_url'] =  'http://ex.ample/';
    else
        $config['base_url'] =  'http://example.com/';
    

    ( I'm using at the local server a virtual host called ex.ample, change this to your needs)

    in my folder assets I store assets/css/style.css

    and call it in my view with:

    <link rel="stylesheet" type="text/css" href="/assets/css/style.css" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器