phphtmlcodeigniter-4

Codeigniter4: pictures with correct paths in html are not loading


I have simple codeigniter4 project setup from tutorial docs: https://codeigniter4.github.io/userguide/tutorial/static_pages.html

the problem is that browser isn't showing pictures even though the src paths are correct. As you can see below i tried using url helper, tried relative paths but nothing works. I even deleted .htacces file but still nothing. Important thing is that this is codeigniter issue since i tried this in my vanilla project and it works.

<img src="<?php echo base_url('/public/imgs/glacier.jpg')?>" alt="glacier">
<img src="/public/imgs/orbs.jpg" alt="orbs">

My pictures are in public/imgs folder. This is error from browser console:

Loading failed for the <script> with source “http://localhost:8080/codeigniter4/index.php?debugbar”. home:6:1

I only begun using codeigniter4 so this is really upsetting to me. Its driving me crazy :(

PS.I hope i've provided all the info required, since this is my first question. I'm looking forward to answers :)


Solution

  • base_url(); outputs the path you have add in your App.php file under config Folder when you open App.php you will find

    public $baseURL = 'http://localhost:8080/' 
     
    

    change this to your preference path eg: public $baseURL ='http://your-domain-name/your-project-name/