嗨,我有问题调用另一个控制器动作发送邮件,这是我的代码:
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?
我建议在路径/库中创建一个新文件夹'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();
$this->action('action', 'controller', 'module', 'params')
该视图助手遍历frontController并再次调度所有插件。
我认为不是最好的解决方案,请记住浪费资源
请尝试此代码$this->action("action","controller","module")