CodeIgniter - Simple base_url question

限于喜欢 提交于 2019-11-28 13:13:00

I think your problem is that base_url is a function in ci 2+ so try this instead

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

It depends how you defined base_url if you did an ending slash otherwise just add a slash so

/css/style.css

I put my css files in the root directory and link them like this

<?php echo link_tag('css/forie.css'); ?>  
<?php echo link_tag('css/reset.css'); ?>
<?php echo link_tag('css/main.css'); ?>

Using link_tag allows me to access them easily

You can use the URL helper to ease your URL woes :)

http://codeigniter.com/user_guide/helpers/url_helper.html

Usage

Load it up in your bootstrap

$this->load->helper('url');

And whenever you need something you can use

echo site_url("/css/style.css");

Or just assign it as a handy base url so you can use it wherever you want.

$base_url = site_url('/');
<link href="{$base_url}css/style.css" rel="stylesheet" type="text/css" />
<?php echo 'base url is' . $base_url?>

Note

Remember to define your proper base URL in the config file before using this method.

for CI 2+ you can add $this->load->helper('url'); before you load the view and then add <link href="<?php echo base_url().'css/style.css';?>" rel="stylesheet" type="text/css" /> into your view file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!