且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Codeigniter中加载图像?

更新时间:2023-11-10 13:10:40

因为你已经使用url帮助我建议包装您的image src属性与base_url,例如:

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

和另一个答案中提到的一样,***(强制?

  class Caller extends CI_Controller {... 

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.

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 { ...