您好我有一节课:
class allConstants {
//PREDEFINED ALL FIXED GROUPS USING IN ACCOUNT MODULE
const GROUP_BANK_ACCOUNT = 'Bank Accounts';
const GROUP_CURRENT_ASSETS = 'Current Assets';
const GROUP_LOAN_LIBILITIES = 'Loan (Liabilities)';
const GROUP_BANK_OD_ACCOUNT = 'Bank OD a/c';
const GROUP_CASH_IN_HAND
}
所以我想将这些常量访问到twig文件中。所以,当我在树枝上使用时,如下 常数(' \埃杜\ AccountBundle \常量\ allConstants :: GROUP_BANK_ACCOUNT&#39);
它表现出一种“常数”的反思错误。没有定义。 请指导如何使其工作。我正在使用symfony 2.3.7 提前致谢
答案 0 :(得分:0)
{% if gropu is constant('allConstants::GROUP_BANK_ACCOUNT') %}
the status attribute is exactly the same as allConstants::GROUP_BANK_ACCOUNT
{% endif %}
测试来自对象实例的常量
{% if gropu is constant('GROUP_BANK_ACCOUNT', allConstants) %}
the status attribute is exactly the same as allConstants::GROUP_BANK_ACCOUNT
{% endif %}
答案 1 :(得分:0)
穆罕默德发布的代码是对的:
{% if group is constant('GROUP_BANK_ACCOUNT', allConstants) %}
the status attribute is exactly the same as allConstants::GROUP_BANK_ACCOUNT
{% endif %}
但你只能使用这样的Twig> = 1.12.1;对于较低版本,您可以在静态类中使用它,如下所示:
constant('allConstants::GROUP_BANK_ACCOUNT')