0

I don't know why it doesn't work I am trying to view profile image. the path is in database and $data['pic'] shows the path but I think the syntax is wrong Thx in advance :)

<img src="/images/<?php echo $data['pic']->pic_path; ?>">

This is var_dump($data['pic']) as you see you see pic_path has a value in it

object(Profile_model)#3 (12) { ["user_id"]=> NULL ["username"]=> NULL ["f_name"]=> NULL ["l_name"]=> NULL ["phone"]=> NULL ["email"]=> NULL ["address"]=> NULL ["height"]=> NULL ["weight"]=> NULL ["goal"]=> NULL ["_connection":protected]=> object(PDO)#4 (0) { } ["pic_path"]=> object(Profile_model)#8 (12) { ["user_id"]=> NULL ["username"]=> NULL ["f_name"]=> NULL ["l_name"]=> NULL ["phone"]=> NULL ["email"]=> NULL ["address"]=> NULL ["height"]=> NULL ["weight"]=> NULL ["goal"]=> NULL ["_connection":protected]=> object(PDO)#9 (0) { } ["pic_path"]=> string(27) "5caf5df7b2ee68.41908466.jpg" } }
<img src="/images/<?php echo $data['pic']->pic_path; ?>">
0

1 Answer 1

3

From what you provided in your question, I can see that $data['pic']->pic_path is an object of type Profile_model, and inside of it, there is another property 'pic_path' which is, in fact, a string. So I believe $data['pic']->pic_path->pic_path would give you the path, but I suspect this is not the intended behavior. I would suggest you double check how an object is being assigned to the first $data['pic']->pic_path.

Sign up to request clarification or add additional context in comments.

5 Comments

You raise a good point about the original assigment to $data['pic']->pic_path.
Thank you so much for the comment, now it finally works but why pic_path is an object? is it because how I sent to view ?
$this->view('profile/index_profile', ['profile'=>$profile,'pic'=>$pic]);
This is how I sent the data from controller to view
I wouldn't say it has to do with the way you send it to the view (suspect you are using Laravel). It is more what value $pic is being assigned before being sent to the view. If you can update your question with the controller code I can try to help you with that.

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.