如何在Codeigniter中加载图像? [英] How to load Images in Codeigniter?
问题描述
嘿,我是一个完全新的Codeigniter.In控制器文件夹中,我创建了一个名为caller.php的文件,我在视图中创建了一个文件home1.php。在根目录中,我创建了一个图像文件夹名称Images并且还创建了一个名为css.In的css文件夹。文件夹中有6张图片。在css文件夹中存在style.css文件。
在caller.php中我写
< ;?
class caller extends CI_Controller
{
function index()
{
$ this-> load-> view('home1');
//这里我必须写这里lo load images ....
}
}
在home1.php中我写
< html&
< head>
< link rel =stylesheettype =text / csshref =<?php echo base_url();?> css / style.css>
//我要写这里加载图片
< / head>
< body>
< div id =outer>
< div id =container>
< div id =images>
< img src =new.jpgwidth =960height =400/>
< img id =image1src =1.jpg/>
< img id =image2src =2.jpg/>
< img id =image3src =3.jpg/>
< img id =image4src =4.jpg/>
< img id =image5src =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>
现在上面的代码如何加载图像。请专家帮助我。
因为你已经使用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 { ...
这篇关于如何在Codeigniter中加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!