ZEND controllers - how to trigger an action from another controller

I want to display a page with two forms. The upper form is unique to this page, but the lower form can already be displayed from another controller. I use the following code to invoke an action of another form, but keep getting this error:

 "Message: id is not specified"

 # 0 ... / library / Zend / Controller / Router / Rewrite.php (441): Zend_Controller_Router_Route-> assemble (Array, true, true)

My code is:

First controller:

abc_Controller
public function someAction()
{

    $this->_helper->actionStack('other','xyz');

}

Second controller:

    xyz_Controller
 public function otherAction()
 {
 // code
 }

Desired Results:

/abc/some "" xyz/ . , (http://framework.zend.com/manual/en/zend.controller.actionhelpers.html), , . ( XDebug), xyz/other , abc/some , - .

.

+3
8

phtml someAction. some.phtml put <?php echo $this->action('other','xyz');?> , otherAction XyzController

+3

- - , . , , , . ,

+3

phtml $this- > action(); , .

:

public function action($action, $controller, $module = null, array $params = array())
+2

( ).

$this->methodFromSecond(); - .

BTW - ?

+1

. , . , phtml, (layout/abc.phtml):

<?php echo $this->render('userNavigation.phtml') ?>

:

echo $this->navigation()->menu()->renderMenu(...)

, .

Akeem hsz . .

, :

  • .
  • $this → _ helper- > actionStack
  • phtml ( "", "xyz" );? > ( Akeem )

, Zend noobs.

0

Hm I can not find and understand why you need to use different controllers for the same kind. Best practice is to have everything in one controller. I use this as in this example

DemoController extends My_Controller_Action() {
 ....
 public function indexAction() {
   $this->view->oForm = new Form_Registration();
 }
}

My_Controller_Action extends Zend_Controller_Action() {
   public function init() {
      parent::init();
      $this->setGeneralStuf();
   }

   public function setGeneralStuf() {
       $this->view->oLoginForm = new Form_Login();
   }
}
0
source

This is the route definition:

routes.abc.route = "abc/buy/:id/*" 
routes.abc.defaults.controller = "deal" 
routes.abc.defaults.action = "buy" 
routes.abc.reqs.id = "\d+"

Requires a parameter to work. You can do this with actionStack, but you can also specify a default identifier if none are provided:

$this->_helper->actionStack('Action',
                            'Controller',
                            'Route',
                            array('param' => 'value')
);


routes.abc.defaults.id = "1" 
0
source

For me it worked like a charm

    class abcController extends Zend_Controller_Action
    {
        public function dashBoardAction()
        {
            $this->_helper->actionStack('list-User-Data', 'xyz');
        }
    }

    class XyzController extends Zend_Controller_Action {
        public function listUserDataAction()
        {
            $data = array('red','green','blue','yellow');
            return $data;
        }
    }
0
source

Source: https://habr.com/ru/post/1724817/


All Articles