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

How to send data to a layout from controller (layouts/head_and_foot.phtml)

In this following code. How to send data to the layout?

class IndexController extends Phalcon\Mvc\Controller 
{
    public function initialize()
    {
        $this->view->setTemplateAfter('head_and_foot');
       /// ???? 
    }
    public function indexAction()
    {
       $this->view->pick('index/body');
    }

}


3.0k
Accepted
answer

:-| I've found the answer. I should have use Phalcon\Tag. It's cleaner.

public function initialize()
{
$this->view->setTemplateAfter('head_and_foot');
$this->view->setVar('varName','varValue')
}

Hello can you help me on how to pass the data from database into my view that is index.phtml . Also how to render the data in for loop in the phtml. I am a beginner with phalcon any help will be appreciated do let me know if you need any more information