Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] base_url from controller?
#1

[eluser]wakey[/eluser]
Hi,

This may be a silly question, but I'm not sure...

I would like to possibly echo the $base_url(); from my controller.

I am using an ajax request to retrieve data which is echoed from my controller to view. The problem is that I could do with using $base_url(); in the link that I am echoing out but can't seem to do it within the controller.

Is this possible?

Thanks in advance.
#2

[eluser]hccoder[/eluser]
hello,

Try: echo $this->config->item('base_url');
#3

[eluser]Phil Sturgeon[/eluser]
You are mixing variables and function names there wakey.

If you have the url_helper loaded you can echo base_url();
#4

[eluser]wakey[/eluser]
Thanks for your help and replies.

Sorry phil, got mixed up when posting here, I usually just use echo base_url(); as you put.

Cheers hccoder, managed to get around this by using - $url = $this->config->item('base_url');
and then echoing $url as part of the url.
#5

[eluser]Phil Sturgeon[/eluser]
You can echo base_url() anywhere if the URL helper is loaded correctly. Put it in the autoload.php helper array perhaps?
#6

[eluser]wakey[/eluser]
I have the URL helper loaded in the autoload.php - I think this is a case of me being a bit thick!

This is the line that I am echoing from the controller to my view -

Code:
echo "<li><href = '$url"."admin/$row->admission'><strong>$row->surname</strong>&nbsp;$row->first_name</a></li>";

(Changed so that I can add it to the forum - didn't realise it blocked urls)

So basically I would need the base_url(); to replace the $url variable but I can't seem to get it in the correct syntax!
#7

[eluser]Phil Sturgeon[/eluser]
That line is wrong in a few ways.

1. Inefficient
2. Invalid HTML
3. The wrong way to create URL's

The code tag is ripping out tags like a nutter, so put this on pastie.

http://pastie.org/851406
#8

[eluser]wakey[/eluser]
Thanks for the tips Phil, very useful.

Looking at it now, I can see how I was going wrong and I have no idea why I was coding the URL like that when I know I've done it the proper way in the past!!

Thanks again, all sorted now!
#9

[eluser]dare[/eluser]
[quote author="Phil Sturgeon" date="1267633353"]That line is wrong in a few ways.

1. Inefficient
2. Invalid HTML
3. The wrong way to create URL's

The code tag is ripping out tags like a nutter, so put this on pastie.

http://pastie.org/851406[/quote]

you saved my life ... many thanks




Theme © iAndrew 2016 - Forum software by © MyBB