too long

I am using zend framework 2.1. I am trying to load the output of my indexAction from my login controller inside of my index controller. The end result I am trying accomplish is to just have my login form loaded on the index page as if it is part of that view.

I have searched for a few hours with no avail. I have attempted to use $this->view->action, which i've seen in earlier versions of zf2 but that has not worked either.

Any information would be helpful.

Taken from this blog, which explains in depth why $this->view->action() has been removed from ZF2, an example how to use the forward() (ZF2 documentation) controller plugin:

You can forward all necessary data to another controller inside your index controller action using the forward() controller plugin like this:

public function indexAction() {
    $view = new ViewModel();

    $login_param = $this->params('login_param');
    $login = $this->forward()->dispatch('App\Controller\LoginController', array(
        'action' => 'display',
        'login_param' => $login_param
    ));

    $view->addChild($login, 'login');

    return $view;
}

In your view, all you need to do is:

<?php echo $this->login; ?>

Please note that the forward() plugin might return a Zend\Http\PhpEnvironment\Response instead. This happens if you use a redirect() in your login controller / action.


Also, if the Servicemanager claims to not find App\Controller\LoginController, have a look in your module.config.php. Look for a section called controllers.
Example:

[...]
'controllers' => array(
    'invokables' => array(
        'LoginCon' => 'App\Controller\LoginController',
        'IndexCon' => 'App\Controller\IndexController',
        'DataCon' => 'App\Controller\DataController',
    )
),
[...]

Here, there is an alias for your login controller called LoginCon, you should use this name as controller name in the dispatch() method instead.