Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Created February 21, 2015 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdmunir/119a55bdbe329c600f1c to your computer and use it in GitHub Desktop.
Save mdmunir/119a55bdbe329c600f1c to your computer and use it in GitHub Desktop.
Penggunaan yii2-upload-file
<?php
// class User
class User extends ActiveRecord
{
...
public function behaviors()
{
return [
[
'class' => 'mdm\upload\UploadBehavior',
'savedAttribute' => 'avatar_id', // <- untuk nyimpan id file
],
];
}
}
?>
// Cara mengakses avatar
<?= Yii::$app->user->identity->username ?>
<?= Html::img(['/file', 'id' => $model->Yii::$app->user->identity->avatar_id]) ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment