属性和方法之一都不存在并且在类中具有公共访问权限,但存在

问题描述 投票:0回答:1

我有一个完全不明白的问题。

“selected”属性和“selected()”、“getselected()”/“isselected()”/“hasselected()”或“__call()”方法之一都不存在,并且在“App”类中具有公共访问权限\Twig\Components\MenuItem".

所选财产的定义明确且精美,并且位于公共场所。我不知道问题是什么

// 
<?php

namespace App\Twig\Components;

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent]
final class MenuItem
{
    public string $selected;
}
       :class="{'rotate-180': (selected ==='{{ this.selected }}')}"
      ></i>
    </a>
  {% else %}
    <a
      x-init="console.log('{{ this.selected }}')"
symfony twig
1个回答
0
投票

创建 TwigComponents 时,您不会执行 {{ this.var }} 来引用在 PHP 类中创建的变量,而是使用更简单的 {{ var }},如此处文档的第一个示例中所述: https:/ /symfony.com/bundles/ux-twig-component/current/index.html

使用 {{ selected }} 而不是 {{ this.selected }} 可以解决您的问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.