3

Hi i have issue here of calling another controller action to send an mail, here is my code:

user.php

public function followAction()
{
     $follow_id = $this->_getParam('id');
     $response = "<a href='javascript: void(0)'  class='i-wrap ig-wrap-user_social i-follow_small-user_social-wrap'><i class='i i-follow_small-user_social ig-user_social'></i>Stop Following</a>";

     notifyEmail()  ------> need to call Notity Controller with notifyEmail() Action along with           
                       params
     $this->_helper->json($response);  ----> return json response
}

NotifyController.php

<?php

class NotifyController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */

    }

     public function index()
    {

    }

     public function notifyEmailAction()
    {
          // rest of email code goes here
    }

}

Thanks for help!

1
  • You can write an action helper and put the email sending code in there. Zend Action Helper Commented Jan 19, 2013 at 4:52

3 Answers 3

8

You have to move send mails functionality to another place, and call it in both methods.

Check this thread Calling member function of other controller in zend framework?

I suggest to create at the path /library a new folder 'My' and in it new file Utilities.php and in that file a new class where you can put all your help methods

class My_Utilities {
    // put here your custom help methods
}

You need to auto-load that namespace.In configs/application.ini put

autoloaderNamespaces.my = "My_"

Then you can use namespace My_ and class My_Utilities.


In any case, you can call method form another controller:

include 'NotifyController.php';
$a = new NotifyController($this->_request, $this->_response);
$a->notifyEmailAction();
Sign up to request clarification or add additional context in comments.

1 Comment

Or instead of a global utilities class, a service object.
2
$this->action('action', 'controller', 'module', 'params')

That view helper walk through frontController and dispatch all plugins again.

I think is not the best solution keep in mind wasting resources

Comments

-1

Please try this code $this->action("action","controller","module")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.