Zend Framework 调用另一个控制器操作 [英] Zend Framework calling another Controller Action
问题描述
我在这里遇到了调用另一个控制器操作来发送邮件的问题,这是我的代码:
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
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
}
}
感谢您的帮助!
推荐答案
您必须将发送邮件功能移到另一个地方,并在两种方法中调用它.
You have to move send mails functionality to another place, and call it in both methods.
检查这个线程在zend框架中调用其他控制器的成员函数?
我建议在路径/library 中创建一个新文件夹My",并在其中创建一个新文件 Utilities.php,并在该文件中创建一个新类,您可以在其中放置所有帮助方法
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
}
您需要自动-加载该命名空间.在 configs/application.ini 中放入
You need to auto-load that namespace.In configs/application.ini put
autoloaderNamespaces.my = "My_"
然后您可以使用命名空间 My_ 和类 My_Utilities.
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();
这篇关于Zend Framework 调用另一个控制器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!