Ajay Gohel
Ajay Gohel

Reputation: 128

Typo3 Fluid extbase- How to execute external controller?

I have 2 different extension. I want to execute second controller (external) inside my first controller

Two different extension 1. Course , 2. Search

class CourseController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
    /**
    * courseRepository
    *
    * @var \TYPO3\Courses\Domain\Repository\CourseRepository
    * @inject
    */
    protected $courseRepository = NULL;
    /**
     * action list
     *
     * @return void
     */
    public function listAction() {
        /** I want to access Search extension Controller (f.e searchRepository->listAction() )**/       
    }
}

class SearchRepository extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
    /**
    * searchRepository
    *
    * @var \TYPO3\Courses\Domain\Repository\SearchRepository
    * @inject
    */
    protected $searchRepository = NULL;
    /**
     * action list
     *
     * @return void
     */
    public function listAction() {
        $searches = $this->searchRepository->findAll();
        $this->view->assign('searches', $searches);         
    }
}

Upvotes: 1

Views: 1317

Answers (1)

stmllr
stmllr

Reputation: 652

tl;dr:

Within a Controller, you usually forward() or redirect() to delegate to a different ControllerAction, e.g. delegate to SearchController::listAction() of 'myExtensionKey':

$this->forward('list', 'Search', 'myExtensionKey');

or

$this->redirect('list', 'Search', 'myExtensionKey');

Long version:

Quote from the MVC documentation of Flow which is quite similar to Extbase MVC:

Often, controllers need to defer execution to other controllers or actions. For that to happen, TYPO3 Flow supports both, internal and external redirects:

  • in an internal redirect which is triggered by forward(), the URI does not change.

  • in an external redirect, the browser receives a HTTP Location header, redirecting him to the new controller. Thus, the URI changes.

The APIs are:

public void forward(string $actionName, string $controllerName=NULL, string $extensionName=NULL, array $arguments=NULL)

protected void redirect(string $actionName, string $controllerName=NULL, string $extensionName=NULL, array $arguments=NULL, integer $pageUid=NULL, int $delay=0, int $statusCode=303)

The programming API details can be found in the Extbase API

Upvotes: 1

Related Questions