Hi there. I’m new to PHP in general and picked Yii as my chosen framework of choice
I'm using the Yii-app tutorial. I have a field 'avatar' that contains an avatar for each record. What class do I use to return the image in the list, show, and update views?
Simple. Add an avatar field to your user table. Then add this to your _post.php view.
<?php echo $post->author->avatar; ?>
It's a very crude method but it SHOULD do the rest for you. You can just wrap that in image tags and add an if empty statement to set a default avatar if you like.
Not sure if that's the cleanest way to do it but it does work. If an avatar is set it prints the URL stored in the database. If it is not set (null) Then it prints a default avatar of your choosing. Remember though if you do this that the database HAS to default to null. If it's only blank I don't think it'll work.
Oh, and if someone would like to clean that up and do it better, Please be my guest. I'm sure there has to be a cleaner way to do this.
Thanks Bios and Jonah. The avatars are saved as links and are pulled from Joomla's Community Builder component image folder. I'm creating an engine to update profiles so I need a preview of the avatars in all records.