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 manage part of the layout who need some specific processing ?

Hi everybody,

I'm starting to use Phalcon and I'm faced to this issue :

My website's menu (displayed on every page), contains some information who need some specific processings (to check users rights, to display a number of messages stored in the database, ...).

In Symfony they used "component" which is like a small controller that you can call directly from a view.

Do you have any idea ?

Thanks



940
Accepted
answer

Hi @mbois,

in Phalcon you can also use components and plugins. Here is an example on how INVO uses Phalcon\Mvc\User\Component: https://github.com/phalcon/invo/blob/master/app/library/Elements.php



537
edited Mar '14

Thx for the answer !

EDIT :

Just to complete I prefered used partial to avoid HTML code mixed with PHP.

<?php

use Phalcon\Mvc\User\Component;

class LayoutElements extends Component {

  public function getMenu() {

    // preparing some stuff to display
    $list = array('...');

    return $this->view->partial('layouts/menu', array('list' => $list));
  }
}

can u share what is your layouts/menu looks like?