How to create a dynamic menu in symfony

Although I found that the PHP Symfony framework is wonderful for many things, it's hard for me to create easily scalable dynamic menus for a website.

I am wondering how other Symfony developers have handled this problem. I will give a simple example of what I ask.

If you go to www.fool.com, you will see that they have a typical menu setting. A list of categories with one of them is active, which is somehow highlighted by CSS.

What would be a good way to make this dynamically created in a Symfony project. Passing variables from some kind from module to module. I have not yet found an elegant solution.

+3
source share
1 answer

, / , . (, ):

$this->menu = array(
    'Home' => array('default', 'index'),
    'About Us' => array('default', 'aboutUs'),
    'Products' => array('products', 'index')
);

getActionName getMethodName , :

$this->current = array_search(array($this->getModuleName(), $this->getActionName()), $this->menu);

$menu , . $current, , "" <li> .

fool.com, , , . , , , , Propel.

+4
source

Source: https://habr.com/ru/post/1703273/


All Articles