volt and controller phalcon example

Solutions on MaxInterview for volt and controller phalcon example by the best coders in the world

showing results for - "volt and controller phalcon example"
María
15 May 2018
1{# app/views/posts/show.phtml #}
2<!DOCTYPE html>
3<html>
4    <head>
5        <title>{{ title }} - An example blog</title>
6    </head>
7    <body>
8        {% if true === showNavigation %}
9        <ul id='navigation'>
10            {% for item in menu %}
11                <li>
12                    <a href='{{ item.href }}'>
13                        {{ item.caption }}
14                    </a>
15                </li>
16            {% endfor %}
17        </ul>
18        {% endif %}
19
20        <h1>{{ post.title }}</h1>
21
22        <div class='content'>
23            {{ post.content }}
24        </div>
25
26    </body>
27</html>```
28
29Usando [Phalcon\Mvc\View](view) puede pasar variables desde el controlador a las vistas. En el ejemplo anterior, se pasaron cuatro variables a la vista: `showNavigation`, `menu`, `title` y `post`:
30
31```php
32<?php
33
34use MyApp\Models\Menu;
35use MyApp\Models\Post;
36use Phalcon\Mvc\Controller;
37use Phalcon\Mvc\View;
38
39/**
40 * @property View $view
41 */
42class PostsController extends Controller
43{
44    public function showAction()
45    {
46        $post = Post::findFirst();
47        $menu = Menu::findFirst();
48
49        $this->view->showNavigation = true;
50        $this->view->menu           = $menu;
51        $this->view->title          = $post->title;
52        $this->view->post           = $post;
53
54        // Or...
55
56        $this->view->setVar('showNavigation', true);
57        $this->view->setVar('menu',           $menu);
58        $this->view->setVar('title',          $post->title);
59        $this->view->setVar('post',           $post);
60    }
61}
62Copy