嗨,我在这里有另一个调用控制器动作来发送邮件的问题,这是我的代码:

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
    }

}

感谢帮助!

最佳答案

您必须将发送邮件功能移到另一个地方,
并在两种方法中都调用它。

检查这个线程
Calling member function of other controller in zend framework?

我建议在路径/ library中创建一个新文件夹“My”,并在其中创建新文件Utilities.php,并在该文件中创建一个新类,您可以在其中放置所有帮助方法。

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

您需要auto-load that namespace。在configs / application.ini中
autoloaderNamespaces.my = "My_"

然后,您可以使用名称空间My_和类My_Utilities。

无论如何,您可以从另一个控制器调用方法:
include 'NotifyController.php';
$a = new NotifyController($this->_request, $this->_response);
$a->notifyEmailAction();

关于php - Zend框架调用另一个Controller Action,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14391413/

10-14 12:53
查看更多