Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

base_url() function not working in codeigniter

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> 
like image 420
Sanks R Avatar asked Jun 23 '11 04:06

Sanks R


People also ask

What is Base_url () in CodeIgniter?

base_url() is the URL of your CodeIgniter root or the location of the index. php file along with a trailing slash appended to the end of the URL. If the domain name is example.com and the website is using HTTPS as well as www. Further, the index.

What is Base_url () in php?

Base URL is used to create internal web page links dynamically in the website. You can get the base URL from the full URL string using PHP. The parse_url() function helps to parse components from URL in PHP. The base URL can be retrieved from a string using PHP parse_url() function.

What is the difference between Site_url and Base_url?

Basically one can use site_url() while creating links for controllers whereas base_url() can be used where we need to create urls for the assets like loading a css or js file or some image .

What is URL Helper in CodeIgniter?

CodeIgniter's URL helpers are groups of utility functions which will help you to call ,create and maintain url. It mainly have more than 20 helpers some of them you might be familiar with are URL, email, form etc. These are some common helper functions that generaly used in web based application for email, files, URLs.


1 Answers

In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (on or around line 67):

$autoload['helper'] = array('url'); 

Or, manually:

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

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:

echo base_url(); 

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 this (base_url) is not set then CodeIgniter will guess the protocol, domain and path to your installation.

application/config/config.php, line 13

like image 86
Sampson Avatar answered Sep 28 '22 00:09

Sampson