title: CakePHP 3: Accessing current user in model
body: <p>Since i'm new to CakePHP, I have simple problems I cannot figure out.</p>
  
  <p>I use CakePHP 3.4. I try to write a simple logger functionality. Every change applied to a record, I want to be logged to the ChangeLog model.</p>
  
  <p>Using afterSave() event, I have following code:</p>
  
  <pre><code>public function afterSave($event, $entity, $options) {
    $logTable = TableRegistry::get('ChangeLogs');
    foreach ($entity-&gt;getDirty() as $key) {
      if($key != 'modified') {
        $record = $logTable-&gt;newEntity();
        $record-&gt;previous_value = $entity-&gt;getOriginal($key);
        $record-&gt;new_value = $entity[$key];
        $record-&gt;table_name = 'Stars';
        $record-&gt;column_name = $key;
        $record-&gt;row_id = $entity-&gt;id;
        $record-&gt;user_id = [what should i put here?]
        $record-&gt;user_id = $_SESSION['Auth']['user']['id'];
        $logTable-&gt;save($record);
      }
    }
  </code></pre>
  
  <p>It works well, but I also want to know which user performed operation and I don't know how can I obtain current user in the Model.</p>
  
  <p>I try to avoid passing argument in controller, because I want user to be detected automaticly, and as a developer I don't want to remember about it every time I try change/add new functionalities in controller.</p>