I know it's possible to obtain the current user through a plugin's controller, but is there a way to get the current user while inside a plugin model?
Basically I'm trying to use the beforeSave model event to set the current users id as the "last_edited_by" field:
public function beforeSave()
{
$this->last_edited_by = //need to get the current logged in users id
}
I also tried writing a custom update controller action to do the job. I was able to get the current logged in user's id, but I couldn't figure out how to pass that to the standard form behavior method:
public function update($recordId, $context = null)
{
//provides the current user's ID, but how do I pass it to the update method below?
//$this->user->attributes['id']
// Call the FormController behavior update() method
return $this->asExtension('FormController')->update($recordId, $context);
}
It looks like the controller is the place to handle logic like that so I would prefer to use the controller update action to accomplish the task.
Any advice/guidance is greatly appreciated.
Last updated