• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial code not working for site_url and some inconsistencies in site_url

#1
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/
Reply

#2
How about this?
PHP Code:
$config['base_url'] = 'http://localhost/ci_host/'
Do you want to write tests for your apps? Our book, CodeIgniter Testing Guide would help you.
Reply

#3
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.
Reply

#4
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 )
Reply

#5
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?
Do you want to write tests for your apps? Our book, CodeIgniter Testing Guide would help you.
Reply

#6
(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.
Do you want to write tests for your apps? Our book, CodeIgniter Testing Guide would help you.
Reply

#7
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.