title: CakePHP 3.0 Custom Event Implementation
body: <p>I was testing out the Events System on CakePHP v3.0.0-RC2 for my project purposes. I first have to apologise for the long text.</p>
  
  <p>Basically I created a users table with fields id, name, and surname. I then created another table called user_statistics that tallies number of user creations per month. Below is the function that saves a user, create an event for the UserStatistics table object and then finally dispatch the event.</p>
  
  <pre><code>use Cake\Event\Event;
  class UsersTable extends Table
  {
    //Other code
     public function createUser($user)
     {
        if( $this-&gt;save( $user )){
  
          $event = new Event('Model.User.afterPlace', $this, array( 
             'user' =&gt; $user 
            ));
  
          $this-&gt;eventManager()-&gt;dispatch( $event );
  
          return true;
         }
        return false;
      }
    }
  </code></pre>
  
  <p>This functions does what its expected - partially so - as it does not seem to dispatch the event but only save the user data. Perhaps the issue lies with the UserStatistics table object. Below is a code snippet of how I have implemented the function that handles tallying of users. </p>
  
  <pre><code>use Cake\Event\EventListenerInterface;
  
  class UserStatistics extends Table implements EventListenerInterface
  {
     //Code ommitted for in account of relevence
  
      public function tallyUsers( $event )
      {
         $data = array();
         if(!empty($event-&gt;subject()-&gt;user)){
  
            $date = date('Y-m-d');
  
            // Check existing record of today 
            $record = $this-&gt;find()-&gt;where(array('date' =&gt; $date));
  
            if(empty($record)){
  
               //Insert new record if none exist for the current date
               $data = array(
                 'date' =&gt; $date,
                 'count' =&gt; 1
               );
             }else{
  
               //Update record if date exist by incerementi count field by one
               $count = (int) $record-&gt;count + 1;
  
               $data = array(
                  'id' =&gt; $record-&gt;id,
                  'date' =&gt; $date,
                  'count' =&gt; $count
                 );
             }
  
            if($this-&gt;save($data))
              return true;
            else
              return false;
          }
      }
  }  
  </code></pre>
  
  <p>After this I had a little misunderstanding as to where I am suppose to register the UserStatistics such that its able to observe the User object. Ofcourse I have implemented the implementedEvents() method on my UserStatistics table object (see below):</p>
  
  <pre><code>public function implementedEvents()
  {
     return array(
        'Model.User.afterPlace' =&gt; 'tallyUsers'
      );
  }
  </code></pre>
  
  <p>I figured out that I should register my observer(UserStatistics) inside the UsersController. Below is how I went about doing it: </p>
  
  <pre><code>...
  publiv function add()
  {
     if($this-&gt;request-&gt;is('post')){
  
        $this-&gt;loadModel('UserStatistics');
        $this-&gt;Users-&gt;eventManager()-&gt;on( $this-&gt;UserStatistics );
  
        if($this-&gt;Users-&gt;createUser( $user )){
          ....
        }
     }
  }
  </code></pre>
  
  <p>Question(s):</p>
  
  <ol>
  <li>How can I access the array user passed on the Users table object i.e. array( 'user' => $user )? </li>
  <li>What does the return true or false suppose to do inside the createUser method on Users table object?</li>
  <li>Did I pass my observer object on my subject model inside the controller?</li>
  <li>Should my UserStatistics tallUsers() method return anything?</li>
  </ol>
  
  <p>Please help me understand as I couldnt find clear readings on this subject from the doc itself or any other place.</p>