zend-frameworkzend-framework3zend-view

nested view with child, child won't be shown


I'm still learning about ZF3. I wanted to test different methods of nested views. First I tried partials, that works.

Now for comparisson reasons I wanted to do the same with a child-view. That doesn't work. Because I did the the same with the partial before, I'm really sure that my models work quite fine, so there is no problem, must be my code for adding the child.

Here ist my controlleraction (I left the partial variety toggled):

    public function showtestAction()
    {
        $adapter = $this->authService->getAdapter();

        if(!$this->authService->hasIdentity())
        {
            return $this->redirect()->toRoute('index', ['action' => 'index']);
        }
        else {
            $parameter = $this->params()->fromRoute('id');
            $part =substr($parameter,0,strpos($parameter,"-"));
            $dclid=substr($parameter, strripos($parameter,"-")+1, strlen($parameter));
            $test3=str_replace('-'.$dclid,'',$parameter);
            $unit=substr($test3, strpos  ($test3,"-")+1, strripos  ($test3,"-")-1);

            if (!empty($parameter)) {
                $view= new ViewModel([
                    'dcls' => $this->table->fetchPartDcl($part,$dclid),
                ]);
               // optional      $view->setTemplate('import/pcb/showtest.phtml');
               $padview= new ViewModel([
                     'pads'=> $this->padtable->fetchPadPart($part, $unit, $dclid)
               ]);     
               $padview->setTemplate('import/pcb/showpad.phtml');

               $view->addChild($padview,'pads');
               return $view;

                //test partial

//              return new ViewModel([
//                  'dcls' => $this->table->fetchPartDcl($part,$dclid),
//                  'pads' => $this->padtable->fetchPadPart($part, $unit, $dclid),
//              ]);
                //ende test partial
            }
        }
    }

Problem is, the child doesn't work, it is not there. I added a h2 headline to control it.

My child template is saved under: module\Import\view\child\showpad.phtml

Where is my error? Any help appreciated!


Solution

  • in template of $view (import/pcb/showtest.phtml) add: echo $this->pads;