D
D
Dmitry Morozov2017-02-21 19:02:04
Zend Framework
Dmitry Morozov, 2017-02-21 19:02:04

How to call another controller from zf2 controller and get its template?

For example, we have an IndexController:

<?php

namespace ZfcIndex\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
  public function indexAction() {
   return nev ViewModel();
  }
}

It will show the standard view which is in view/index/index.phtml.
But for example, I want to call another function from this function, for example, UserController::indexAction and get its view and instead of the standard view that exists, show the view and process the event of the UserController controller.
Wanted to try through ServiceManager:
$controller =  $this->serviceManager->get('ZfcLogin\Factory\Controller\UserControlleFactoryr');
$class = $controller->{'indexAction'}();

But alas, except for json, I didn’t get anything (It’s understandable). Can someone tell me how to get another view controller from 1 without using the ViewModel.
PS I know about the router that it is easier through it, but I specifically need this, that when checking, going to site.ru/, I was shown a view based on the ZfcIndex controller or, based on ZfcLogin.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Morozov, 2017-02-21
@index1

Found the answer:
return $this->forward()->dispatch('Controller', array('action' => 'action'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question