Claudio
Claudio

Reputation: 15

Call to undefined function base_url()

I get this error when I try to load base_url funcion. The problem is that I've already added base_url to autoload file but the issue still:

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

views/home.php file has the following code:

    <!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div align="center">
    <h1>Index</h1>
    <a href="<?= base_url()?>">Link</a>
</div>

</body>
</html>

Any ideas? Since base_url function is being loaded by autoload I don't know what else should I try to do to fix this.

Thank you!

Upvotes: 1

Views: 13362

Answers (2)

darkangel
darkangel

Reputation: 120

Change <a href="<?= base_url()?>">Link</a> with <a href="<?=base_url()?>">Link</a>. Do not add space when you are using short tags.

Upvotes: 0

user4419336
user4419336

Reputation:

It could be that your not echoing the base_url

Try this

<?php echo base_url();?>

Instead of

<?= base_url()?>

As you have shown you are all ready auto loading url helper

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

Make sure in CI3 versions base_url is not empty in config.php

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

Wamp

www > project >
www > project > application 
www > project > system
www > project > index.php

Xampp

htdocs > project >
htdocs > project > application 
htdocs > project > system
htdocs > project > index.php

Update: with the code you have provide in link

--

There were many bugs. I would start of will a fresh copy.

1: In your autoload.php you had two $autoload['helpers'] = array(); I removed the empty one and worked. Where line 85 and 93 remove that and you will see on line 42 there is same.

2: In your config.php this $config['index_page'] = 'home.php'; should be $config['index_page'] = 'index.php';

3: Your controller filesnames did not have there first letter uppercase.

Filename Home.php

<?php 

class Home extends CI_Controller {

}

Upvotes: 4

Related Questions