Open bkrajendra opened 8 years ago
This is when $this->user is not defined, e.g. if no user is logged in. You need to make sure you always pass a User object there, otherwise you will get an error. You can use this workaround, if you cant ensure you always have a logged in user:
$user = !is_null($this->user) ? $this->user : new User;
Got it working as follows: Make sure this component is placed by code initiation not by dragging it on page.. A better way is to add it dynamically by using following code on onInit of code section of a page. Assuming we want to add avatar/profile pic for account page, add :
{% component 'imageUploader' %}
anywhere you want to put upload box. For example in my case I've added above line in update.htm partial (overridden) of user component. This will display upload box in account page above update account form.
After this add following code to account page code section:
function onInit ()
{
$user = Auth::getUser();
if($user){
$component = $this->addComponent(
'NetSTI\Uploader\Components\ImageUploader',
'imageUploader',
['modelClass'=>'RainLab\User\Models\User','modelKeyColumn'=>'avatar', 'deferredBinding' => false]
);
$component->bindModel('avatar', $user);
}
}
Here modelClass is the class in which to relate picture (avatar) and modelKeyColumn is the column name to which this pic to relate.
@bkrajendra Your code snippet did not fix the issue for me. Anyone got something else that works?
I'm getting error:
I'm using following code in my component :
Ive also tried in Page Init method but its showing same error.