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

[resolved]How to manage an object query by Pages::findFirstById($id);

        #PagesController code#
          $page = Pages::findFirstById($id);
            if (!$page) {
                $this->flash->error("Page was not found.");
                return $this->forward("pages/index");
            }

        //print_r($page);
        **// how to assign $page to volt templat and how manage the $page in volt template.**
        $this->view->

        #volt template code #
            .....

        Thanks for your help.


2.4k
edited May '16

> controller code: $this->view->page = $page;

> volt template code: <article> <h3>{{ page.title }}</h3> <p>{{ page.ctime}}</p> <div>{{ page.body }}</div> </article>



11.0k

did you try with this document ? https://docs.phalcon.io/en/latest/reference/volt.html

use for loop to access data in array variable



12.2k
Accepted
answer

In controller:

$this->view->setVars(
    [
        'page' = $page,
    ]
);

In volt


{{ page }}  #object

{{ page.id }}       # access id property of page (prints it)