简体   繁体   English

在smarty模板中使用php class属性

[英]Using php class property in smarty template

Can i use php class static properties in smarty template? 我可以在smarty模板中使用php类的静态属性吗? For example: 例如:

class UserData
{
    const INDEX = 1;
    const STREET = 2;

    static public $_address_fields = array(
        self::INDEX,
        self::STREET 
    );
}

And in my smarty template i want do something like this: 在我的模板中,我想做这样的事情:

{UserData::$_address_fields}

Is it possible? 可能吗?

You can pass this in from your controller 您可以从控制器中传入

For example: $smarty->assign('AddressFields, UserData::$_address_fields); 例如: $smarty->assign('AddressFields, UserData::$_address_fields);

This should then be available for use in your template like so: {$AddressFields} 然后,可以在模板中使用它,如下所示: {$AddressFields}

Smarty Docs: https://www.smarty.net/docsv2/en/api.assign.tpl Smarty Docs: https//www.smarty.net/docsv2/en/api.assign.tpl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM