The base_url () function does not work in codeigniter

I am developing an application using codeigniter. I am trying to use the base_url () function, but it shows empty results. I used the autoloader through the autoload file, but then it also does not work. I also defined the basic 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> 
+49
php codeigniter
Jun 23 2018-11-11T00:
source share
7 answers

To use base_url() , you must first load the url. This can be done either in application/config/autoload.php (on line or around line 67):

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

Or, manually:

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

After downloading it, be sure to remember that base_url() does not imply printing or echoing, but returns the value that will be printed:

 echo base_url(); 

Remember also that the return value is the URL of the site database as specified in the configuration file. CodeIgniter will also contain an empty value in the configuration file:

If this (base_url) is not installed, CodeIgniter will guess the protocol, domain and path to your installation.

application / config / config.php line 13

+122
Jun 23 '11 at 4:40
source share

If you want to use base_url() , we need to load the URL helper.

  • Using autoload $autoload['helper'] = array('url');
  • Either manually load the controller or in sight $this->load->helper('url');

Then you can use the base_url() user anywhere in the controller or view.

+4
Jul 29 '14 at 10:06
source share

Check if you have something configured inside the configuration file /application/config/config.php for example.

 $config['base_url'] = 'http://example.com/'; 
+2
Jun 23 '11 at 4:45
source share

I think you have not edited the codeigniter files to include base_url () . you are trying to assign it to url_helper.php, you can also make the same config / autoload.php file. you can add this code to your autoload.php file

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

How can you use ue base_url () like this

 <link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" /> 
+2
Mar 22 '15 at 5:53
source share

If you do not want to use the url helper, you can get the same results using the following variable:

 $this->config->config['base_url'] 

It will return the base url for you without additional steps.

0
Feb 17 '15 at 23:36
source share

First of all, download the helper url. you can download the file "config / autoload.php" and add the following code $autoload['helper'] = array('url');

or in the controller add the following code

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

then go to config.php in the cofig folder and install

 $config['base_url'] = 'http://urlbaseurl.com/'; 

hope this helps thanks

0
May 2 '17 at 10:11
source share

First of all, you have to upload url helper file to your project

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

Then you will get base_url on

 echo base_url(); 

More about base_url here

0
Nov 13 '17 at 1:19 on
source share



All Articles