How to set a automatically base url?


i just wrote a code in a view and have set a base url as below:
<base href="<?php echo "$base"; ?>">
now when i load an image in my view i have given like this

<img src="echo $base/images; /catch-me.gif" alt="catch-me"/>

but i have to write
like this
<img src="images/catch-me.gif" alt="catch-me"/>

i mean that can't it set the base url automatically like normally we do when we are developing a project.
now i have to write as
sorry to sttach the sample file because it was not getting pasted over here!

[eluser]Eric Barnes[/eluser]
A base href tag ads the domain part to every link on the page. So for instance:
&lt;base href="" /&gt;

<img src="images/test/3.gif" />
<img src="images/catch-me.gif" />

Hi (Excuse my english)

If you use the &lt;base&gt; tag, you will have to replace "<a href='#'>" with "<a href="[removed];">" in all your views Sad , because the former will not work as expected.

Hmm, forum filters...

[removed] = j a v a script : ;
without the spaces.

Sorry, i didn't read the topic properly...

actually i think you guys not getting question.
sorry but because of forum filters i could not write my code. but will try that as below.

i have set a base url as shown previously the i wrote a image tag as below
< i m g s r c = " ? php " e c h o $ baseurl /"i m a g e s /c a t c h m e.gif" >
but cant i write like this as below
< i m g s r c = "i m a g e s /c a t c h m e.gif" >
means it will automatically take the base url, without me having to specify?

Eric gave you the answer above!

In your config.php file autoload the url helper.

then add this between the head tags.

&lt;base href="&lt;?php echo base_url(); ?&gt;" /&gt;

This assumes that your image directory is in your root were index.php is.

And please use the CODE TAGS!


you mean to say that i should write the below code
when i wrote above line in my config i got the error

Fatal error: Using $this when not in object context in config.php on line 2

Load it in your controller...
I just don't get why you would want you base url in an image tag...:S...
just create a map in your root called public
then create a map called images
put you pics in there and your src will be:
<i m g sr c=" /public/images/picture.jpg " />
Maybe I misunderstood to but this would be my way...

EDITED: srry didn't see/know it would be filtered

hey i cant see the code u mentioned above coz of form filters i guess.
And when
i only
give this
<img src ="image/catchme.gif">
it does not show the image
but when
i write a $base/images/catmes.gif it shows image.
i am confused what is happening

Sorry meant to say load it in your autoload.php file in the config directory.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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