We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Returning views

Hi People ! i have a project structure using modules and i want to use once of my controllers, from a module, to get a view (like a helper). i.e: ProductsViewController->getListView();

Which is the correct method to do this? basiclly i have problems returning the html from the view, i try to using differents options like $this->view->pick('list') , $this->view->render , etc ... but it doesn't work. The goal here is return the html to pass it to a volt view in another controller in the best way.

Thanks in advance.



58.4k

Hey

Can you upload code on github. I will support it

Thanks Thien ! it could take a long time ! i'll try to do that =) I have a modules bootstrap loading differents routes

  • apps/products/config/routes.php
  • apps/products/controllers/ProductsViewController.php
  • apps/products/views/list.volt
  • apps/site/config/routes.php
  • apps/site/controllers/SiteViewController.php
  • apps/site/views/site.volt

From SiteViewController I need to do something like this:

$productList = ProductsViewController::getProductList();
$this->view->productList = $productList;
$this->view->pick('index'); // picking the site's index located in site/index.volt

Then in the volt {{ productList }}, it should be simple!

I am trying to use ViewControllers to focus them to return views from methods or picking views from actions.

Hey

Can you upload code on github. I will support it



58.4k

You try this

    return $this->view->pick($this->router->getControllerName() . '/index');