Welcome Guest, Not a member yet? Register   Sign In
base_url() and url helper
#1

[eluser]elaniobro[/eluser]
Having issues with the config.php file and setting the base URL.

I currently have my config.php file setting my base pat as follows:
Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5/system/application";

However when I use the url helper anchor():
Code:
<?= anchor('/thoughts/more/'.$row->id, 'read');?>

I get a 404:

The requested URL /www.example.com/com/5/system/application/index.php/thoughts/more/2 was not found on this server.


However, if I change the config to the following:
Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5

Removing '/system/application' from the end of the base URL, the anchor() works properly, but no images/css/js etc.. works.

Any ideas?
#2

[eluser]jedd[/eluser]
[quote author="elaniobro" date="1267326365"]Having issues with the config.php file and setting the base URL.
I currently have my config.php file setting my base pat as follows:
Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5/system/application";
[/quote]

In my copy of CI, the config.php includes a comment just above the $config['base_url'] section that reads:

Code:
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:

Is yours different?
#3

[eluser]elaniobro[/eluser]
In my copy of CI, the config.php includes a comment just above the $config['base_url'] section that reads:

Code:
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:

Is yours different?[/quote]


No, mine is the same. Perhaps my folder structure is not set up correctly.
I have my site living here:

system/application/mysite

Is this not correct? Should it be moved? maybe that would alleivate the issues I am having.
#4

[eluser]jedd[/eluser]
[quote author="elaniobro" date="1267326365"]
Removing '/system/application' from the end of the base URL, the anchor() works properly, but no images/css/js etc.. works.
[/quote]

You might want to show:
a) your code for pulling in images (are you using img() for example?)
b) your code for pulling in css and js etc (are you using link_tag() for example?)
c) the web-browser's page source for these same sections
d) your .htaccess file

The section in the wiki on [url="/wiki/How_to_ask_a_good_question/"]how to ask a good question[/url] covers some of the kinds of information that's handy to provide with this sort of problem. The [url="/wiki/FAQ"]FAQ[/url] (also in the wiki) is a good thing to read through first to see if a question has already been answered.
#5

[eluser]jedd[/eluser]
If yours is the same, why don't you use a trailing slash on your base_url then?
#6

[eluser]jedd[/eluser]
To spell it out, you almost definitely want this:

Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5/";

(Judging from what you've revealed so far.) My earlier observations (regarding other info to show us) still stand.
#7

[eluser]elaniobro[/eluser]
[quote author="jedd" date="1267337753"]To spell it out, you almost definitely want this:

Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5/";

(Judging from what you've revealed so far.) My earlier observations (regarding other info to show us) still stand.[/quote]

a) your code for pulling in images (are you using img() for example?)
no I am using:
Code:
<img src="&lt;?= base_url();?&gt;img/logo_tagline.png"/> &lt;!-- for example --&gt;
b) your code for pulling in css and js etc (are you using link_tag() for example?)
Code:
&lt;link type="text/css" href="&lt;?= base_url();?&gt;com/css/global.css" rel="stylesheet" media="screen" /&gt;
c) the web-browser’s page source for these same sections
You want a link to my actual site?

d) your .htaccess file
non existent at the moment.

Hope those answers gives you more insight. I am new to CI, and have read through the wiki, but will most certainly go back and comb through it again. I appreciated your help thus far.

I might add that I am using MAMP for local dev.
#8

[eluser]elaniobro[/eluser]
LIVE
Code:
$config['base_url']    = "http://www.example.com/5/system/application";

MAMP
Code:
$config['base_url']    = "http://localhost:8888/www.example.com/com/5/system/application";
#9

[eluser]jedd[/eluser]
[quote author="elaniobro" date="1267338545"]LIVE
Code:
$config['base_url']    = "http://www.example.com/5/system/application";
[/quote]

Don't do that. Do this instead (as I've already suggested)
Code:
$config['base_url']    = "http://www.example.com/5/";



[quote author="elaniobro" date="1267338545"]
[/code]
<img src="&lt;?= base_url();?&gt;img/logo_tagline.png"/>
[/code]
[/quote]

Don't do that. Do this instead

Code:
img('img/logo_tagline.png');

Have a play with it - taking note of your page-source in your browser - and see how you go. You can also look at your web server (apache) access and error logs, to see what files (say logo_tagline.png) it's trying to find, and where it's looking for it in the file system - this is often very instructive in these kinds of cases.
#10

[eluser]elaniobro[/eluser]
-Jedd

Thanks, I will certainly give it ago. As for the img(); does that need to have a helper loaded, or is that built in to the core? Also what is the benefit of using img(); vs base_url() within the <img> tag?




Theme © iAndrew 2016 - Forum software by © MyBB