In my web application using codeigniter. I am trying to use base_url() function but it shows empty results. I have also used autoload helper through autoload file, but then too it doesn’t seem to work. Also I had defined base constants but all in vain.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
<script type="text/javascript">
//<![CDATA[
base_url = '<?= base_url();?>';
//]]>
</script>
</head>
In order to use
base_url(), you must first have the URL Helper loaded. This can be done either inapplication/config/autoload.php(on or around line 67):Or, manually:
Once it’s loaded, be sure to keep in mind that
base_url()doesn’t implicitly print or echo out anything, rather it returns the value to be printed:Remember also that the value returned is the site’s base url as provided in the config file. CodeIgniter will accomodate an empty value in the config file as well: