Zend Framework calling another Controller Action

2019-07-21 03:17发布

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!

3条回答
ゆ 、 Hurt°
2楼-- · 2019-07-21 04:10

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

查看更多
Explosion°爆炸
3楼-- · 2019-07-21 04:15
$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

查看更多
可以哭但决不认输i
4楼-- · 2019-07-21 04:16

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();
查看更多
登录 后发表回答