Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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');
    }

}


1.9k
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