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