代码之家  ›  专栏  ›  技术社区  ›  pia-sophie

带子级的嵌套视图,不会显示子级

  •  0
  • pia-sophie  · 技术社区  · 7 年前

    我还在学习ZF3。我想测试嵌套视图的不同方法。首先我尝试了partials,这很有效。

    现在出于比较的原因,我想对子视图也这样做。这行不通。因为我以前也对partial做过同样的操作,我确信我的模型工作得很好,所以没有问题,一定是我添加子项的代码。

    这是我的controlleraction(我让部分变体处于切换状态):

        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
                }
            }
        }
    

    问题是,孩子不工作,它不在那里。我添加了一个h2标题来控制它。

    我的子模板保存在以下位置:模块\导入\视图\子模板\显示板。phtml

    我的错误在哪里?感谢您的帮助!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Ichte    7 年前

    在$view(import/pcb/showtest.phtml)的模板中添加: echo$此->垫;