0

Goal: I am trying to show an image in the view.ctp. I am trying to grab the image that was saved with the rest of the information. I am pretty sure the code is 100% correct in the ProductsController, if not that'll be posted next.

Here is the code in the view.ctp for products:

<h1>Viewing  Product</h1>

<div><b>Name:</b> <?php echo $Product['Product']['name']; ?></div>

        <div>
            <img src="<?php echo $path .'/'. $row['Product']['filename']; ?> "  width="300px" /> 
        </div>

<div><b>Description:</b> <?php echo $Product['Product']['description']; ?></div>
<div><b>Price:</b> <?php echo $Product['Product']['price']; ?></div>

1 Answer 1

1

Read down a bit to see the actual solution.

Shoudln't

        <img src="<?php echo $path .'/'. $row['Product']['filename']; ?> "  width="300px" /> 

be:

        <img src="<?php echo $path .'/'. $Product['Product']['filename']; ?> "  width="300px" /> 

?

Since the original poster actually answered their own question I thought I'd elaborate.

The Solution:

Replacing:

        <img src="<?php echo $path .'/'. $row['Product']['filename']; ?> "  width="300px" /> 

with:

        <?php echo $this->Html->image('$Product['Product']['filename']') ?> 
Sign up to request clarification or add additional context in comments.

4 Comments

And shouldn't it all be replaced with $this->Html->image(...)? :)
webdesign4.georgianc.on.ca/~100141468/comp2084/todo/products/… That did not work. How would it look with $this->Html->image?
@drHannibalLecter: I wouldn't know because I don't know anything about CakePHP, but that seems to make more sense.
<?php echo $this->Html->image ('$Product['Product']['filename']') ?> Yeah I am not very sure where I am getting to

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.