Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

}

Thanks for help!

like image 847
Saraswathi Apavoo Avatar asked Apr 21 '26 10:04

Saraswathi Apavoo


2 Answers

You have to move send mails functionality to another place, and call it in both methods.

Check this thread Calling member function of other controller in zend framework?

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
}

You need to auto-load that namespace.In configs/application.ini put

autoloaderNamespaces.my = "My_"

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();
like image 66
tasmaniski Avatar answered Apr 22 '26 23:04

tasmaniski


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

That view helper walk through frontController and dispatch all plugins again.

I think is not the best solution keep in mind wasting resources

like image 26
user3442629 Avatar answered Apr 23 '26 00:04

user3442629