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.

[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.


1.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>



8.1k

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

use for loop to access data in array variable



6.6k
Accepted
answer

In controller:

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

In volt


{{ page }}  #object

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