Shakir Hossain Shakir Hossain - 2 months ago 14
CSS Question

How to load Images in Codeigniter?

Hey i am totally new in Codeigniter.In the Controllers folder I created a file named caller.php and I created a file home1.php in Views. In root directory i created a image folder name Images and also created a css folder named css.In images Folder there are 6 picture. In css folder style.css file exist.

In caller.php i write

<?
class caller extends CI_Controller
{
function index()
{
$this->load->view('home1');

// what i have to write here lo load images....

}
}


In home1.php i write

<html>
<head>

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">

// what i have to write here to load images


</head>

<body>
<div id="outer">

<div id="container">

<div id="images">
<img src="new.jpg" width="960" height="400"/>
<img id="image1" src="1.jpg" />
<img id="image2" src="2.jpg" />
<img id="image3" src="3.jpg" />
<img id="image4" src="4.jpg" />
<img id="image5" src="5.jpg" />
</div>

<div id="slider">
<a href="#image1">1</a>
<a href="#image2">2</a>
<a href="#image3">3</a>
<a href="#image4">4</a>
<a href="#image5">5</a>
</div>
...................................................
....................................................
</div>

</div>


</body>

</html>


Now for the above code how i load the images .Please experts help me.
if additional config's are needed please mention that.

Answer

As you're already using the url helper I suggest wrapping your image src attributes with base_url, such as:

<img src="<?php echo base_url('images/1.jpg'); ?>" />

And as mentioned in the other answer it's best (mandatory?) to capitalize the class name in your controller

class Caller extends CI_Controller { ...