Base_Url() Function Not Working in Codeigniter

base_url() function not working in codeigniter

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

Base_url() not working on codeigniter

in config.php set this line

$config['base_url'] = 'http://localhost/register/'; 

root directory set this way

application
system
bootstrap-3.3.6

base url for code igniter site not working

You are not using the base_url in your HTML code, you are currently "manually" loading the assets:

<link href="/assets/css/global.css" rel="stylesheet" type="text/css" media="all" />

The / at the start tells the browser to load the assets from the root folder.

You can use the base_url() function to generate links, this function is available if you load the URL helper, you can use it like this:

base_url('assets/css/global.css');

This will return:

http://xxx.xxx.xx.xxx/blah.com/assets/css/global.css

So use it like this:

<link href="<?=base_url('assets/css/global.css');?>" rel="stylesheet" type="text/css" media="all" />

<?= is the same as <?php echo

You can load the URL helper with this code:

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

Route or base_url is not working properly in CodeIgniter

From the given information with little assumptions, I think you're making your navbar like:

<a href="home">Home</a>

Whereas, you must add the base_url() like this:

<a href="<?= base_url('home'); ?>">Home</a>

Let me know, if you have some problem.

Update

From the provided HTML code:

<li class="nav-item "> 
<a class="nav-link" href="<?php base_url();?>home">
HOME <span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php base_url();?>about">ABOUT</a>
</li>

Replace <?php base_url(); ?>

To <?php echo base_url();?> OR <?= base_url();?>

Codeigniter base_url not working when deleting, adding and updating the data

If you want to used base_url. First step, You must have to URL helper loaded in your application/config/autoload.php

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

Or you can load URL Helper Manually by

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

Then You can call base_url like

echo base_url();

But Remember One thing,

If this base_url is not set in your config.php file then CodeIgniter will get the protocol,
domain and path to your installation.

But If you are define base_url in your application/config/config.php then base_url is loaded from here.



Related Topics



Leave a reply



Submit