I am developing a we application using codeigniter. I am trying to use base_url() function but it shows empty results. I have 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. Please help.
<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>
If you want to use
base_url()
, so we need to load url helper.$autoload['helper'] = array('url');
$this->load->helper('url');
Then you can user
base_url()
anywhere in controller or view.First of all load URL helper. you can load in "config/autoload.php" file and add following code
$autoload['helper'] = array('url');
or in controller add following code
then go to config.php in cofig folder and set
hope this will help thanks
Check if you have something configured inside the config file
/application/config/config.php
e.g.First of all you must load the url helper file to your project
Then you will get base_url by
Read more about base_url here
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:
If you don't want to use the url helper, you can get the same results by using the following variable:
It will return the base url for you with no extra steps required.