I have the directory structure like this in code igniter:
Appsite
-website
-application
-images
When I accessing the image in index.php I used:
<img src="http://localhost/Appsite/website/images/images.PNG"
And the href is:
<li class=""><a href="http://localhos/tAppsite/website/index.php/home/">Home</a></li>
I think it is not a good practice to include the http://localhost
when accessing the images or libraries in code igniter. So I tried to change the $config['base_url']
in config.php
to $config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";
And now I update my image source and other library source I remove the localhost and the name of my directory folder:
<img src="images/images.PNG”>
<li class=""><a href= <?php echo base_url;?> /website/index.php/home/">Home</a></li>
But I get errors. it says object not found. Can some help me?
In your
config.php
set thebase_url()
as,In your view load the image as,
In Config.php
In
.htaccess
(outside application folder) - To removeindex.php
in URLTo accessing URL
To access image
To access CSS
To use
base_url
load URL helper from autoload.phpJust put this it will take the automatically correct path of the project and set base URL