CodeIgniter Forums

Full Version: Tutorial code not working for site_url and some inconsistencies in site_url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I started CodeIgniter recently and found few inconsistencies which I could not understand:

In this page:
https://www.codeigniter.com/user_guide/t...ction.html#

It says to use code:

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

But User guide for same at :
https://www.codeigniter.com/user_guide/h...elper.html

Says to use following code:
$this->load->helper('url');

Why two different versions?

Now comes my real problem:
$config['base_url'] = 'localhost/ci_host/'; // This was also not mentioned in tutorial.

My relevant code for application/views/news/index.php 
is following:

<?php echo "Base url: ". base_url('news');?>
<?php echo "Site url: ". site_url('news');?>
<?php echo "Slug: ". $news_item['slug'];?>
<p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p>

And out put for same is: 
Base url: localhost/ci_test/news
Site url: localhost/ci_test/index.php/news
Slug: new_item_1
Base url for slug: localhost/ci_test/news/new_item_1


View article

And "View article" takes me to following link:
http://localhost/ci_test/index.php/localhost/ci_host/index.php/news/new_item_1

But inspect on "View Article" shows following:

<a href="localhost/ci_host/index.php/news/new_item_1">View article</a>

Would be great to take me out of this.

Totally baffling me ...
My codeigniter base is located at: http://localhost/ci_test/
How about this?
PHP Code:
$config['base_url'] = 'http://localhost/ci_host/'
Wow..that works. Thanks a lot @kenjis .

Putting http:// really helped.

By any chance, could you enlighten me on why this happened? I am ready to get deep into the code.

But frankly these tidbits is what, pushes me away from using Frameworks. I am hoping these are less in CodeIgniter as it is very lightweight.
When loading a helper you drop the _helper off of it and just use the name url_helper becomes url
First, I recommend you read the comment for $config['base_url'].
PHP Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value! 
`localhost/ci_host/` is not correct URL.


Quote:And "View article" takes me to following link:
http://localhost/ci_test/index.php/localhost/ci_host/index.php/news/new_item_1

But inspect on "View Article" shows following:
<a href="localhost/ci_host/index.php/news/new_item_1">View article</a>
Perhaps you are at `http://localhost/ci_test/index.php/` and the href is `localhost/ci_host/index.php/news/new_item_1`.
So you will go `http://localhost/ci_test/index.php/localhost/ci_host/index.php/news/new_item_1`. Right?
(03-01-2017, 12:21 AM)bhagwandas Wrote: [ -> ]But frankly these tidbits is what, pushes me away from using Frameworks. I am hoping these are less in CodeIgniter as it is very lightweight.

Yes, conventions in CodeIgniter are less than any other frameworks.
But it still has some.
Thanks a lot @kenjis .

Reinforced my faith in CodeIgniter.

All my doubts are cleared now. I was taking it wrong because of my poor understanding with html.