Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
registerClass()
2
 
3
register a class for use in the templates
4
 
5
Description
6
===========
7
 
8
void
9
 
10
registerClass
11
 
12
string
13
 
14
class\_name
15
 
16
string
17
 
18
class\_impl
19
 
20
Smarty allows you to access static classes from templates as long as the
21
[Security Policy](#advanced.features.security) does not tell it
22
otherwise. If security is enabled, classes registered with
23
`registerClass()` are accessible to templates.
24
 
25
 
26
    <?php
27
 
28
    class Bar {
29
      $property = "hello world";
30
    }
31
 
32
    $smarty = new Smarty();
33
    $smarty->registerClass("Foo", "Bar");
34
 
35
 
36
 
37
 
38
    {* Smarty will access this class as long as it's not prohibited by security *}
39
    {Bar::$property}
40
    {* Foo translates to the real class Bar *}
41
    {Foo::$property}
42
 
43
 
44
 
45
 
46
    <?php
47
    namespace my\php\application {
48
      class Bar {
49
        $property = "hello world";
50
      }
51
    }
52
 
53
    $smarty = new Smarty();
54
    $smarty->registerClass("Foo", "\my\php\application\Bar");
55
 
56
 
57
 
58
 
59
    {* Foo translates to the real class \my\php\application\Bar *}
60
    {Foo::$property}
61
 
62
 
63
 
64
See also [`registerObject()`](#api.register.object), and
65
[Security](#advanced.features.security).