# How to call private function from Controller to another Controller (Plugin)

**URL:** <https://discourse.cakephp.org/t/how-to-call-private-function-from-controller-to-another-controller-plugin/4495>\
**Category:** Need Help\
**Created:** [June 30, 2018, 6:14am UTC](https://discourse.cakephp.org/t/how-to-call-private-function-from-controller-to-another-controller-plugin/4495 "2018-06-30T06:14:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zakblack](https://avatars.discourse-cdn.com/v4/letter/z/b9bd4f/32.png) [@zakblack](https://discourse.cakephp.org/u/zakblack)\
**Post date:** [June 30, 2018, 6:14am UTC](https://discourse.cakephp.org/t/how-to-call-private-function-from-controller-to-another-controller-plugin/4495/1 "2018-06-30T06:14:08Z")

</div>

I have a plugin Events,

I would like to add this part

UsersController.php

```
   private function sendResetEmail($url, $user) {
    $email = new Email();
    $email->template('resetpw');
    $email->emailFormat('both');
    $email->from('no-reply@naidim.org');
    $email->to($user->email, $user->full_name);
    $email->subject('Reset your password');
    $email->viewVars(['url' => $url, 'username' => $user->username]);
    if ($email->send()) {
        $this->Flash->success(__('Check your email for your reset password link'));
    } else {
        $this->Flash->error(__('Error sending email: ') . $email->smtpError);
    }
}

```

To this part

EventController (INSIDE PLUGINS)

```
 $event = $this->Events->newEntity();
    if ($this->request->is('post')) {
        $event = $this->Events->patchEntity($event, $this->request->data);
        if ($this->Events->save($event)) {
            //function send_mail to user who crated Event
            EventManager::instance()->on(
            'Model.Events.afterNotify',
            $aCallback
            );
            $this->Flash->success(__('The event has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The event could not be saved. Please, try again.'));
        }
    }
```

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [July 1, 2018, 10:39pm UTC](https://discourse.cakephp.org/t/how-to-call-private-function-from-controller-to-another-controller-plugin/4495/2 "2018-07-01T22:39:11Z")

</div>

Try to setup a listener [https://book.cakephp.org/3.0/en/core-libraries/events.html#registering-listeners](https://book.cakephp.org/3.0/en/core-libraries/events.html#registering-listeners)

You could also see if anyone has done any videos on youtube on cakephp 3.x events.
