在我的布局中,我想通过id沙龙获得salon_edit的视图。
这是symfony2错误&#34;变量&#34;沙龙&#34;不存在&#34;在lign 61 - &gt; <a href="{{ path('salon_edit', { 'id':salon.id }) }}" class="link_pink">Mon compte salon</a>
你能帮我吗?
以下是这个木杆的枝条部分
<ul class="nav navbar-nav navbar-right">
<li>
{% if is_granted('ROLE_SALON') %}
<a href="{{ path('salon_edit', { 'id':salon.id }) }}" class="link_pink">Mon compte salon</a>
{% elseif is_granted('ROLE_USER') %}
<a href=# class="link_pink">Mon compte</a>
{% endif %}
</li>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
<li>
<a href="{{ path('fos_user_security_logout') }}" class="link_rouge">Se déconnecter</a>
</li>
{% else %}
<li>
<a class="link_pink" href="{{ path('user_inscription') }}">S'inscrire</a>
</li>
{% endif %}
</ul>
这是来自saloncontroller的功能
/**
* Displays a form to edit an existing salon entity.
*
* @Route("/{id}/edit", name="salon_edit")
* @Method({"GET", "POST"})
*/
public function editAction(Request $request, Salon $salon)
{
$deleteForm = $this->createDeleteForm($salon);
$editForm = $this->createForm('SalonBundle\Form\SalonType', $salon);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('salon_edit', array('id' => $salon->getId()));
}
return $this->render('@Salon/salon/edit.html.twig', array(
'salon' => $salon,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
堆栈跟踪
[1] Twig_Error_Runtime: Variable "salon" does not exist.
at n/a
in /var/www/html/salon-beaute/src/CoreBundle/Resources/views/Default/layout.html.twig line 61
at __TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82->{closure}()
in /var/www/html/salon-beaute/app/cache/dev/twig/66/66beb7ecc8aa1a0e9315e0eddb676910b6afc28c60b27e59e4cc417df7bde814.php line 128
at __TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82->block_header(array('app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_stylesheets'), 'header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body'), 'javascripts' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_javascripts'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4577
at Twig_Template->displayBlock('header', array('app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_stylesheets'), 'header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body'), 'javascripts' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_javascripts'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer')))
in /var/www/html/salon-beaute/app/cache/dev/twig/7a/7a92fc34297bb697cff5b7a080558e7f9d95ea471251008ab1f7e7390b0deb5a.php line 51
at __TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528->doDisplay(array('app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_stylesheets'), 'header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body'), 'javascripts' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_javascripts'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4682
at Twig_Template->displayWithErrorHandling(array('app' => object(AppVariable)), array('title' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_title'), 'stylesheets' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_stylesheets'), 'header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body'), 'javascripts' => array(object(__TwigTemplate_5cc24ee05b63b1a2f964871f6daa7de9297002ce6686929eddf463a4e536a528), 'block_javascripts'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4663
at Twig_Template->display(array('app' => object(AppVariable)), array('header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/twig/66/66beb7ecc8aa1a0e9315e0eddb676910b6afc28c60b27e59e4cc417df7bde814.php line 28
at __TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82->doDisplay(array('app' => object(AppVariable)), array('header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4682
at Twig_Template->displayWithErrorHandling(array('app' => object(AppVariable)), array('header' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_header'), 'footer' => array(object(__TwigTemplate_ff527ec479eaa508e6f0a4dde49c75ec7eaccfdd5401a5e2f3c7a5571c049b82), 'block_footer'), 'body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4663
at Twig_Template->display(array('app' => object(AppVariable)), array('body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/twig/ee/ee83aa46a744063fbc1dae1a5d8c7745a1257cd4f8dc9948b21b4f2f065ab756.php line 27
at __TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6->doDisplay(array('app' => object(AppVariable)), array('body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4682
at Twig_Template->displayWithErrorHandling(array('app' => object(AppVariable)), array('body' => array(object(__TwigTemplate_1dd3d918e01d77f295bef77124491b666956198f387af3b7a6bd384c0793c7a6), 'block_body')))
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4663
at Twig_Template->display(array())
in /var/www/html/salon-beaute/app/cache/dev/classes.php line 4670
at Twig_Template->render(array())
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 50
at Symfony\Bridge\Twig\TwigEngine->render('@Core/Default/homepage.html.twig', array())
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/TwigEngine.php line 72
at Symfony\Bundle\TwigBundle\TwigEngine->render('@Core/Default/homepage.html.twig', array())
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/TwigEngine.php line 99
at Symfony\Bundle\TwigBundle\TwigEngine->renderResponse('@Core/Default/homepage.html.twig', array(), object(Response))
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 185
at Symfony\Bundle\FrameworkBundle\Controller\Controller->render('@Core/Default/homepage.html.twig')
in /var/www/html/salon-beaute/src/CoreBundle/Controller/DefaultController.php line 11
at CoreBundle\Controller\DefaultController->indexAction()
in line
at call_user_func_array(array(object(DefaultController), 'indexAction'), array())
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 144
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 64
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 69
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /var/www/html/salon-beaute/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /var/www/html/salon-beaute/web/app_dev.php line 28
答案 0 :(得分:1)
你正在经过一系列称为沙龙的沙龙。如果你想要访问,你必须经过一个树枝循环。所以在你的:
{% if is_granted('ROLE_SALON') %}
<a href="{{ path('salon_edit', { 'id':salon.id }) }}" class="link_pink">Mon compte salon</a>
{% elseif is_granted('ROLE_USER') %}
<a href=# class="link_pink">Mon compte</a>
{% endif %}
你必须修改为:
{% if is_granted('ROLE_SALON') %}
{% for salon in salons %}
<a href="{{ path('salon_edit', { 'id':salon.id }) }}" class="link_pink">Mon compte salon</a>
{%endfor%}
{% elseif is_granted('ROLE_USER') %}
<a href=# class="link_pink">Mon compte</a>
{% endif %}
编辑1:您能否在分析器中提供“请求属性”部分的内容
答案 1 :(得分:0)
如果您尝试访问父模板的变量,请尝试此操作,也许可行
{%set salonParentVar =沙龙%}