Answer the question
In order to leave comments, you need to log in
(Yii2) What is the best way to organize the interaction of the avatar display widget with the avatar manager?
Continuing the question: (Yii2) What is the best way to deal with user avatars?
I'm trying to decide how to make an optimal structure for working with an avatar and displaying it using a widget.
public $user_id;
public function __construct(User $UserModel = null, $config = [])
{
parent::__construct($config);
$this->_UserModel = $UserModel;
}
public function getAvatarUrl()
{
// Возвращает URL картинки
}
public $user_id;
private $_AvatarManager;
public function init()
{
parent::init();
$this->user_id = isset($this->user_id) ? $this->user_id : Yii::$app->user->identity->getId();
$this->_AvatarManager = new AvatarManager(null, ['user_id' => $this->user_id]);
}
public function run($user_id = null)
{
echo $this->content($user_id);
}
public function content($user_id = null)
{
if (isset($user_id))
$this->_AvatarManager->user_id = $user_id;
$img_url = $this->_AvatarManager->getAvatarUrl();
$content = // Генерация контента
return $content;
}
$avatar = new AvatarManager();
$avatar->run(1)
$avatar->run(2)
$avatar->run(3)
...
$avatar->run(10000)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question