CodeIgniter Forums
User placeholder user picture if not set? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Best Practices (https://forum.codeigniter.com/forum-12.html)
+--- Thread: User placeholder user picture if not set? (/thread-77976.html)



User placeholder user picture if not set? - jnar - 11-13-2020

Hello.

I extended myth auth to have user picture, so I can acces that property like this:

PHP Code:
<?= user()->profile_pic ?>

What would the best approach display a stock image if picture is not set?   Should i validate right in the view like this?
PHP Code:
<?php
$userpic 
= !(user()->profile_pic 'custom_pic.jpg : user()->profile_pic;
?>

Or it would be a better practice to do this in the controller and just recieve in the view the pic like a variable already validated?


RE: User placeholder user picture if not set? - jnar - 11-13-2020

Ok nevermind I just created a helper function to handle this