Sar*_*voo 2 php zend-framework
嗨,我有问题调用另一个控制器动作发送邮件,这是我的代码:
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
}
Run Code Online (Sandbox Code Playgroud)
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
}
}
Run Code Online (Sandbox Code Playgroud)
感谢帮助!
您必须将发送邮件功能移动到另一个位置,并在两种方法中调用它.
检查此线程 在zend框架中调用其他控制器的成员函数?
我建议在路径/库中创建一个新文件夹'My',并在其中创建新文件Utilities.php,并在该文件中创建一个新类,您可以在其中放置所有帮助方法
class My_Utilities {
// put here your custom help methods
}
Run Code Online (Sandbox Code Playgroud)
您需要自动加载该命名空间.在configs/application.ini中
autoloaderNamespaces.my = "My_"
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用名称空间My_和类My_Utilities.
在任何情况下,您都可以调用另一个控制器的方法:
include 'NotifyController.php';
$a = new NotifyController($this->_request, $this->_response);
$a->notifyEmailAction();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16352 次 |
| 最近记录: |