Skip to content

registerClass()

在模板中注册一个类以供使用

描述

void

registerClass

string

class_name

string

class_impl

只要安全策略没有禁止,Smarty 允许你从模板中访问静态类。如果启用了安全性,那么使用 registerClass() 注册的类对模板是可访问的。

    <?php

    class Bar {
      $property = "hello world";
    }

    $smarty = new Smarty();
    $smarty->registerClass("Foo", "Bar");




    {* 只要安全性没有禁止,Smarty 将访问此类 *}
    {Bar::$property}
    {* Foo 转译为真实的类 Bar *}
    {Foo::$property}
    <?php
    namespace my\php\application {
      class Bar {
        $property = "hello world";
      }
    }

    $smarty = new Smarty();
    $smarty->registerClass("Foo", "\my\php\application\Bar");




    {* Foo 转译为真实的类 \my\php\application\Bar *}
    {Foo::$property}

参见 registerObject(),以及 安全