PHP code example of brussens / yii2-avatar-behavior
1. Go to this page and download the library: Download brussens/yii2-avatar-behavior library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brussens / yii2-avatar-behavior example snippets
namespace common\models;
use yii\db\ActiveRecord;
use brussens\behaviors\AvatarBehavior;
class User extends ActiveRecord
{
public static function tableName()
{
return '{{%user}}';
}
public function behaviors()
{
return [
'avatarBehavior' => [
'class' => AvatarBehavior::className(),
'attribute' => 'userpic'
]
];
}
}
//Returns user avatar as Html::img()
echo Yii::$app->getUser()->getIdentity()->getThumb(30, 30, [
'class' => 'img-thumbnail'
]);
//Returns user avatar url
echo Html::img(Yii::$app->getUser()->getIdentity()->getThumbUrl(30, 30));
//Some user
$user = User::findOne(1);
echo $user->getThumb(20, 20);
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.