Tutorial code not working for site_url and some inconsistencies in site_url |
02-28-2017, 07:18 AM
(This post was last modified: 02-28-2017, 09:44 PM by bhagwandas. Edit Reason: Set config['base_url'] )
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/local...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
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
First, I recommend you read the comment for $config['base_url'].
PHP Code: /* Quote:And "View article" takes me to following link: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?
|
Welcome Guest, Not a member yet? Register Sign In |