Is there a way to render ViewModel without a template

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Is there a way to render ViewModel without a template

dennis-fedco
This post has NOT been accepted by the mailing list yet.
I want to convert my legacy code to ZF2. But how? Original Code:

        $rows = $this->repository->getModelListing($model);
        if (count($rows) == 0) {
            ?><h3>No products available</h3><?
            return;
        }

My Try:

        if (count($rows) == 0)
        {
            $this->setPhpRenderer('Module');
            $view = new ViewModel();
            $view->setTemplate('no_products.phtml');
            //(new View())->render($model);
            echo $this->renderView($view);
            return;
        }

I found it a bit excessive. Can I not have a Template set and do something else? My concern is that from light-weight code I went to heavy-weigh ViewModel, and (new View())->render().