![]() |
[SOLVED] base_url from controller? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [SOLVED] base_url from controller? (/showthread.php?tid=28120) |
[SOLVED] base_url from controller? - El Forum - 03-02-2010 [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. [SOLVED] base_url from controller? - El Forum - 03-02-2010 [eluser]hccoder[/eluser] hello, Try: echo $this->config->item('base_url'); [SOLVED] base_url from controller? - El Forum - 03-02-2010 [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(); [SOLVED] base_url from controller? - El Forum - 03-03-2010 [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. [SOLVED] base_url from controller? - El Forum - 03-03-2010 [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? [SOLVED] base_url from controller? - El Forum - 03-03-2010 [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> $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! [SOLVED] base_url from controller? - El Forum - 03-03-2010 [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 [SOLVED] base_url from controller? - El Forum - 03-03-2010 [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! [SOLVED] base_url from controller? - El Forum - 08-16-2010 [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 |