zend-frameworkzend-framework3zend-view

folder for view template not found


I'm again searching for the best way to do. I tried a bit with partial-views, it doesn't work the template isn't found.

Here what I did: snippet show.phtml

    foreach ($dcls as $dcl) : 
//var_dump(get_object_vars($importdcls));

?>
    <tr>
    <td><?= $dcl->DCLID?></td>
    <td><?= $dcl->Part_Number?></td>
    <td><?= $dcl->Pad_Number?></td>
    <td><?= $dcl->Pad_Issue?></td>
    <td><?= $dcl->Pad_App?></td>
    </tr>
    <?php echo $this->partial('showpartial', ['pads'=>$pad]);?>
 <?php  endforeach; ?>

I saved the partial in the same folder as the show.phtml

Screenshot partial view

My showpartial.phtml

<?php

$this->title = "Partial";
$this->headTitle($this->titel);
?>
<p></p>

 <tr>

    <td><?= $pad->DCLID?></td>
    <td><?= $pad->Part_Number?></td>
    <td><?= $pad->Pad_Number?></td>
    <td><?= $pad->Pad_Issue?></td>
    <td><?= $pad->Pad_App?></td>

    </tr>

In my controller I give two parameters to the view:

return new ViewModel([
                                    'dcls' => $this->table->fetchPartDcl($id),
                                    'pads' => $this->padtable->fetchPadPart($id),
                                ]);

here also my view_manager configuration:

 'view_manager' => [                                                             //templates für den view_manager
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',                                  //Skript für 404 Fehler
        'exception_template'       => 'error/index',
        'template_map' => [
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'layout/layoutlogin'      => __DIR__ . '/../view/layout/layoutlogin.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],

The error I get:

Zend\View\Renderer\PhpRenderer::render: Unable to render template "showpartial"; resolver could not resolve to a file

because of the error message I think I have still an understanding problem. Here some questions:

  1. What is to do to find the template in this folder, I would expect ZF to find it anyway, because it is in the same folder?
  2. Where would you save the partials? In the view folder of the route or somewhere else. What is recommended?
  3. Is the main idea of using partial in this case a good one?

Solution

  • ok I added a folder partial under my view module folder. Now it works.