I want to redirect to different viewscripts depends on a searchtype the user can fill in.
For example: The user wants to search for a person, than I want to use the matching viewscripts for persons (ansprechpartner). Please have a look at a part of my controller action:
switch ($suche['suchtyp']) {
case 1: //Ansprechpartner
$view = new ViewModel([
'ansprechpartner' => $this->ansprechpartnerTable->sucheAnsprechpartner($suche['suche']),
]);
$view->setTemplate('ansprechpartner/index');
return $view;
break;
case 2: //Mandant
$view = new ViewModel([
'mandant' => $this->mandantTable->sucheMandant($suche['suche']),
]);
$view->setTemplate('mandant/index');
return $view;
break;
case 3: //vertrag
$view = new ViewModel([
'vertrag' => $this->vertragTable->sucheVertrag($suche['suche']),
]);
$view->setTemplate('vertrag/index');
return $view;
break;
default:
return $this->redirect()->toRoute('index', ['action' => 'index']);
}
In the screenshot my folders will be shown:
So how can I use the existing viewscripts in this case, without to call the matching controller actions?
I think you should provide full template path to the setTemplate
, in your switch
$view = new ViewModel([
'ansprechpartner' => $this->ansprechpartnerTable->sucheAnsprechpartner($suche['suche']),
]);
$view->setTemplate('stammdaten/ansprechpartner/index');
return $view;