php
  • zend-framework
  • 2013-01-18 55 views 2 likes 
    2

    嗨,我有問題,這裏調用另一個控制器動作來發送郵件,這裏是我的代碼:Zend框架調用另一個控制器動作

    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 
        } 
    
    } 
    

    感謝您的幫助!

    +0

    你可以寫一個動作助手,把電子郵件發送代碼在那裏。 [Zend Action Helper](http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html) –

    回答

    7

    您必須將發送郵件功能移動到另一個地方 並在兩種方法中調用它。

    檢查這個線程 Calling member function of other controller in zend framework?

    我建議在路徑/庫的新文件夾「我」和它的新文件Utilities.php並在該文件的新類來創建,你可以把所有您的幫助方法

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

    您需要auto-load that namespace。在CONFIGS /的application.ini把

    autoloaderNamespaces.my = "My_" 
    

    然後你才能在美國e命名空間My_和類My_Utilities。


    在任何情況下,你可以調用方法形成另一個控制器:

    include 'NotifyController.php'; 
    $a = new NotifyController($this->_request, $this->_response); 
    $a->notifyEmailAction(); 
    
    +0

    或者不是全局實用程序類,而是一個服務對象。 – blockhead

    -1

    請試試這個代碼 $this->action("action","controller","module")

    0
    $this->action('action', 'controller', 'module', 'params') 
    

    該視圖助手通過frontController走,並再次派遣所有插件。

    我覺得是不是最好的解決辦法記住浪費資源

    相關問題