Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 菜单中的动态链接(Symfony 3)_Php_Symfony_Hyperlink_Menu_Twig - Fatal编程技术网

Php 菜单中的动态链接(Symfony 3)

Php 菜单中的动态链接(Symfony 3),php,symfony,hyperlink,menu,twig,Php,Symfony,Hyperlink,Menu,Twig,我正在与Symfony合作,我想将菜单栏添加到我的网站。我有一个简单的菜单栏与3个链接是静态的,总是像“家”一样,但我需要添加新的链接,应该是动态的。我有我的管理面板,我可以添加新的网页(有关他们的信息存储在数据库-标题,内容等),我想实现的是,在添加一个新的网页,链接到这个页面应该出现在这个菜单。我在header.html.twig文件中有这个菜单,我将它包含到与页脚相同的每一页中 我当时所能达到的最好成绩是: DefaultController.php public function hea

我正在与Symfony合作,我想将菜单栏添加到我的网站。我有一个简单的菜单栏与3个链接是静态的,总是像“家”一样,但我需要添加新的链接,应该是动态的。我有我的管理面板,我可以添加新的网页(有关他们的信息存储在数据库-标题,内容等),我想实现的是,在添加一个新的网页,链接到这个页面应该出现在这个菜单。我在header.html.twig文件中有这个菜单,我将它包含到与页脚相同的每一页中

我当时所能达到的最好成绩是:

DefaultController.php

public function headerAction ()
{
    $news =  $this->getDoctrine()
        ->getManager()
        ->createQueryBuilder()
        ->from('AppBundle:News', 'n')
        ->select('n')
        ->where('n.type = :news')
        ->setParameter('news', 'other')
        ->getQuery()
        ->getResult();

    $parsedown = new Parsedown();
    foreach($news as $key => $new){
        $news[$key]->setContent($parsedown->text($new->getContent()));
    }

    return $this->render('default/other_menu.html.twig', array(
        'news' => $news
    ));
}
header-menu.html.twig

{# some bootstrap #}
{# simple static links #}

{{ render(controller('AppBundle:Default:header')) }}

{# simple static links #}
{# some bootstrap #}
{% for new in news %}
<a href="{{ path('show_other', {id: new.id}) }}">{{ new.title }}</a>
{% endfor %}
other_menu.html.twig

{# some bootstrap #}
{# simple static links #}

{{ render(controller('AppBundle:Default:header')) }}

{# simple static links #}
{# some bootstrap #}
{% for new in news %}
<a href="{{ path('show_other', {id: new.id}) }}">{{ new.title }}</a>
{% endfor %}
{%用于新闻中的新内容%}
{%endfor%}
但这个解决方案只有在数据库中有一个页面时才有效。如果有更多链接,则会创建一个长链接(第1页第2页第3页)


任何帮助都将不胜感激。

尝试进行
转储($news)你们有什么?两元素数组。第一个元素:0=>News{#1166▼     -id:2-标题:“关于我们”-内容:“Lorem ipsum

”-createDate:DateTime{1179▶} -键入:“other”好的,那么这是一个数组,你的Parsedown()是什么?它只是为了标记。当你在细枝模板中转储新闻时?你有一个数组或一个类似page1page2page3的字符串?试着做一个
转储($news);
你有什么?两个元素数组。第一个元素:0=>新闻{1166▼ -id:2-标题:“关于我们”-内容:“Lorem ipsum

”-createDate:DateTime{1179▶} -键入:“other”好的,那么这是一个数组,您的Parsedown()是什么?它只是用于标记。当您在细枝模板中转储新闻时,您有一个数组或一个类似page1page2page3的字符串吗?