1. <?php
  2. namespace App\Controller;
  3.  
  4. use Cake\Mailer\MailerAwareTrait;
  5.  
  6. class UsersController extends AppController
  7. {
  8. use MailerAwareTrait;
  9.  
  10. public function register()
  11. {
  12. $user = $this->Users->newEntity();
  13. if ($this->request->is('post')) {
  14. $user = $this->Users->patchEntity($user, $this->request->data());
  15. if ($this->Users->save($user)) {
  16. $this->getMailer('User')->send('welcome', [$user]);
  17. }
  18. }
  19. $this->set('user', $user);
  20. }
  21. }