1

How can i call a controller::action from another modules controller::action in Zend.

dir tree

-modules
--auth
---controllers
--crm
--default
---controllers

how can i do something like this:

/* module\default\controller */

public function indexAction(){
        $something = \model\auth\IndexController::doSomething();
}

UPDATE:

I know that something like this is possible in CodeIgniter via Modular Extensions see here

$out = modules::run('module/controller/method', $param1, ....);
2
  • Why do you want to do that? What are you trying to accomplish? Commented Jan 20, 2012 at 14:04
  • Lets say that I would like to have a Widget type of functionality, like a mini-cart where that widget has some functionalities and can be placed as a partial anywhere on the site. Commented Jan 25, 2012 at 10:57

4 Answers 4

2

The only thing I know of that will approach that functionality is the ActionStack helper:
ZF Action stack helper
Controllers are not really intended to be called in the same manner as most other methods.

Sign up to request clarification or add additional context in comments.

Comments

1

If you need to call an action from another, without go foward with the flow of your program, so there something wrong like RockyFord said.

Thinking in your explanation about a partial retrieving of information to buil a widget, I would create a helper in the library so it could be called from any place, something like:

-lib
--MyLib
---Controller
----Action
-----Helper
------ Foo.php

The Foo action helper could be:

class MyLib_Controller_Action_Helper_Foo extends Zend_Controller_Action_Helper_Abstract {

   public setBar() { 
      // some code here
   }       

   public getBar() { 
      // some code here for retrieving the partial
   }
}

Then to call it from another controller action or even another lib function

 // in a controller action
 ...
 $foo = new MyLib_Controller_Action_Helper_Foo();
 $foo->setBar();
 $bar = $foo->getBar();
 $this->view->bar = $bar;
 ...

Hope this helps

Namastê !!

Comments

0

If you want to do that, something is probably wrong with your design. Try to move the desired functionality to a third class for example to an action helper and call it from both controllers. That said, it should be possible to do

$a = new A_Controller();
$a->aAction();

or

A_Controller::aAction();

if aAction is declared static. (I have tried neither though.)

Comments

0

I agree with the RockyFord's suggestion that the action stack helper is probably your best bet.

Other solutions might include manually forwarding to another action ssomewhere else in your app with some paramaters.

function fooAction()
{
    // Going to someplace else
    $this->_forward($action, $controller, $module, $params);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.