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

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



685
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?