brussens / yii2-avatar-behavior
Behavior for the transparent operations of avatar thumbnails
Installs: 113
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-behavior
Requires
- yiisoft/yii2: *
- yiisoft/yii2-imagine: ~2.0.0
This package is auto-updated.
Last update: 2024-11-15 01:18:15 UTC
README
#Yii2 avatar behavior Behavior for the transparent operations of avatar thumbnails
##Install Either run
php composer.phar require --prefer-dist brussens/yii2-avatar-behavior "*"
or add
"brussens/yii2-avatar-behavior": "*"
to the require section of your composer.json
file.
##Model configurations Add a new attribute to the user's model, such as "userpic"
Add to your user model:
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' ] ]; } }
Use
//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);