Jump to content
Larry Ullman's Book Forums

Image Of Books Fails To Display Properly In Homepage


matinee
 Share

Recommended Posts

images of books fails to display properly in homepage, broken image is displayed instead.

please solve the problem

 

 

Home » Books
Books
Displaying 1-6 of 6 results.
1.jpg
Title: The Yii Book
Price: $20.00
Author: Larry Ullman
Date Published: Dec. 31, 2024
2.jpg
Title: Effortless E-commerce with PHP and MySQL (2nd Edition)
Price: $44.99
Author: Larry Ullman
Date Published: Nov. 30, 2013
3.jpg
Title: PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Price: $0.40
Author: Larry Ullman
Date Published: Aug. 16, 2012
 
Link to comment
Share on other sites

  • 2 weeks later...

I was actually trying the chapter 23 example, e-commerce site

the code is

 

<?php echo '<img src="/images/'.$model->id.'.jpg">'; ?>

 

It just display a broken picture. The image fails to display properly.

The images are in the images folder

Pliz help

Link to comment
Share on other sites

Okay, good. I assume, then, that the URL you're using is http://localhost/yiiecom. If so, then the values for the img src attributes have to be /yiiecom/images. The default value of /images means the browser will look for the images in the "images" folder in the web root directory, C:\xampp\htdocs\images, in your case. Make that change and you should be good. 

Link to comment
Share on other sites

thanks a lot Larry, now I get the images of the books. The problem is solved

But, what should I do to keep the images folder inside the apllication folder.

How I should modify the code in the "view.php" and "_view.php"  to display the image when the images folder is inside the application folder.

Link to comment
Share on other sites

Hey! So, just to be clear, you never need to post "please help". I will help, or someone else will, but I almost certainly won't get back to you within an hour of when you just posted. Please try to be patient. 

 

I'm not sure I followed your most recent post. Your view files should only need to have the same update as you did for the index file. Just use the proper reference to the images as they're stored on the file system.

 

Also, the images are in the web directory, not within the application folder.

Link to comment
Share on other sites

Finally got it.

 

changing the img src to "/yiiecom/images/ does the job

 

<?php echo CHtml::link('<img src="/yiiecom/images/' . $data->id . '.jpg">', array('view', 'id'=>$data->id)); ?>

 

Why I didn't get it before inspite of it having been explained by you

 

<"Okay, good. I assume, then, that the URL you're using is http://localhost/yiiecom. If so, then the values for the img src attributes have to be /yiiecom/images. The default value of /images means the browser will look for the images in the "images" folder in the web root directory, C:\xampp\htdocs\images, in your case. Make that change and you should be good.">

 

 

Thanks a lot Larry for your valuable help.

Link to comment
Share on other sites

 Share

×
×
  • Create New...