我有一个试图分配给 smarty 变量的接口。在 Smarty 3 中添加了对类内容的支持,我正在尝试利用它。
namespace Application;
interface ServerResponseCodes
{
const FAILURE = 0;
const SUCCESS = 1;
const PENDING = 2;
const INVALID = 3;
}
接着
$smarty->assign("codes", Application\ServerResponseCodes);
抛出错误
致命错误:第 16 行 /home/parvhraban/domains/src/www_root/clienttest.php 中未定义的常量“Application\ServerResponseCodes”
是否可以从 smarty 模板访问接口常量?
是否存在我只能分配初始化对象的限制?
有什么比反射类更好、更原生的解决方案吗?
$codes = new ReflectionClass ('Application\ServerResponseCodes');
$smarty->assign("codes", $codes->getConstants());